Hi, I'm struggling to get a relatively simple PHP/MySQL script to work. Basically, I've got two tables populated with entries from a database.
However I'm getting errors on the second table mysql_num_rows(): supplied argument is not a valid MySQL result resource
and mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Now, I get that this means that haven't been defined, but I should have defined them in a superglobal from the result of a form as follows:
$myfirstname=$_POST['myfirstname'];
$mysecondname=$_POST['mysecondname'];
session_register("myfirstname");
session_register("mysecondname");
Table code:
<div id="news_all" style="float:left">
<h2>News from the team...</h2>
<?php
//DB login
require_once('mysql_login.php');
//$latest = mysql_query("SELECT * FROM messages where tm = (SELECT MAX(tm) FROM messages)");
$query = "SELECT * FROM messages where first_name = 'Milton' and second_name= 'Players'";
$all_msgs = mysql_query($query);
$num = mysql_num_rows($all_msgs);
mysql_close();
echo "<table border='1' width=400px>";
echo "<tr> <th>Date Sent</th> <th>Message</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $all_msgs )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['tm'];
echo "</td><td>";
echo $row['message'];
echo "</td></tr>";
}
echo "</table>";
//dummy text
//include("team_news.txt");
?>
</div>
<div id="news_latest" style="float:left">
<h2>News for you...</h2>
<?php
//DB login
//require_once('mysql_login.php');
$query = "SELECT * FROM messages where first_name = '$myfirstname' and second_name = '$mysecondname'";
$yr_msgs = mysql_query($query);
$num = mysql_num_rows($yr_msgs);
echo "<hr />".$num."<hr />";
mysql_close();
echo "<table border='1' width=400px>";
echo "<tr> <th>Date Sent</th> <th>Message</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $yr_msgs )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $rowb['tm'];
echo "</td><td>";
echo $rowb['message'];
echo "</td></tr>";
}
echo "</table>";
//dummy text
//include("your_news.txt");
?>
</div>