Hello, I am getting this error :
Warning: Supplied argument is not a valid MySQL result resource in d:\home\BestLittleAdSpace.com_mySQL-play\TestGETdata.php on line 32
Below here is my code in 3 files.. The last file is a PUT data process that worked fine storing
data to my table preferences.. Then I used a mySQL FRONT program to actually
go to my HOST who supports PHP & MySQL account and view the preferences table..
After I INSERTED data to the table... I checked to make certain it was there okay
Now trying to read the data from my host table preferences i am erroring at line 32..
I am a newbie beginner... learning the basics.. and using anothers tutorial to work.. I have suspect
that the tutor code might be a problem.. http://coronet.iicm.edu/php/mysql_out.html
I have looked and looked but can't see why its failing
Thanks in advance
======FORM============
<html>
<head>
<title>People's Preferences</title>
</head>
<body>
<center>
Select all users with the following preference:
<p>
<table width = 400>
<tr>
<td align = right>
<form action = "TestGETdata.php" method = "POST">
Preference:
<select name = "preference">
<option value = Movies>Movies
<option value = Music>Music
<option value = Theater>Theater
</select>
<p>
<input type = "submit" value = "Send it!">
</form>
</td>
</tr>
</table>
</center>
</body>
</html>
======TestGETdata.php====================
html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?
/ this script will handle the variables passed from the action4.html file /
/ it outputs the content from the preferences database /
/ that match a specified SQL query /
/ declare some relevant variables /
$hostname = "mySQL.general-hosting.com";
$username = "mmmstrc";
$password = "mmmstrc1999";
$dbName = "mmmstrc";
/ MySQL table created to store the data /
/ this 3 records in it created by tutorial previously... so I know insert is working/
$userstable = "preferences";
/ make connection to database /
MYSQL_CONNECT($hostname,$username,$password) OR DIE("Unable to connect to database");
@mysql_select_db("$dbName") or die("Unable to select database");
/ Select all users with the preference preference /
$query = "SELECT * FROM $userstable WHERE preference = $preference";
$result = MYSQL_QUERY($query);
/ How many of these users are there? /
$number = MYSQL_NUMROWS($result);
/ Print these results to the screen in a nice format /
$i = 0;
IF ($number == 0) :
PRINT "<CENTER><P>Nobody in the database prefers $preference!</CENTER>";
ELSEIF ($number > 0) :
PRINT "<CENTER><P>Users preferring $preference: $number<BR><BR>";
WHILE ($i < $number):
$name = mysql_result($result, $i, "name");
$age = mysql_result($result, $i, "age");
PRINT "Visitor $name likes $preference.<BR>";
PRINT "Age: $age.";
PRINT "<BR><BR>";
$i++;
ENDWHILE;
PRINT "</CENTER>";
ENDIF;
/ Close the database connection /
MYSQL_CLOSE();
?>
</body>
</html>
the ERROR i am getting
Warning: Supplied argument is not a valid MySQL result resource in d:\home\BestLittleAdSpace.com_mySQL-play\TestGETdata.php on line 32
======This is the code is okay that populated data okay into TABLE preferences okay==
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?
/ this script will handle the variables passed from the action3.html file /
/ it outputs further the current date /
/ it inserts the sent data into a MySQL database /
/ declare some relevant variables /
$hostname = "mySQL.general-hosting.com";
$username = "mmmstrc";
$password = "mmmstrc1999";
$dbName = "mmmstrc";
/ MySQL table created to store the data /
$userstable = "preferences";
/ make connection to database /
MYSQL_CONNECT($hostname,$username,$password) OR DIE("Unable to connect to database");
@mysql_select_db("$dbName") or die("Unable to select database");
$today = date("Y-m-d");
PRINT "<center>";
PRINT "Hello, $name.";
PRINT "<br><br>";
PRINT "You are $age years old and you like $preference.<br><br>";
PRINT "Thank you for your cooperation.<br><br>";
PRINT "Today is: $today.<br><br>";
/ Insert information into table /
$query = "INSERT INTO $userstable VALUES('$name','$age', '$preference')";
$result = MYSQL_QUERY($query);
PRINT "Information that you provided has been successfully inserted into our database";
PRINT "</center>";
/ Close the database connection /
MYSQL_CLOSE();
?>
</body>
</html>