futurejp
05-23-2008, 02:26 AM
Hi,
I'm trying out some php/mysql code for the first time, and I'm getting errors while trying some example code from www.w3schools.com.
Here is the page I'm looking at:
http://www.w3schools.com/php/php_mysql_select.asp
and here is the code I'm trying:
<?php
$con = mysql_connect("mysql1.***************","a2080062_mpr","test!!");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("stest", $con);
$result = mysql_query("SELECT * FROM stest2 WHERE Song='Walk This Way'");
echo "<table border='1'>
<tr>
<th>Date</th>
<th>Song</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Date'] . "</td>";
echo "<td>" . $row['Song'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
The error I get on my site says it's with the
while($row = mysql_fetch_array($result))
line, and it says:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a2080062/public_html/test.html on line 21
The table in the database I'm accessing has four columns: "Date," "Venue," "Location," "Song." So a row in this table might look like:
1975-04-19 Boston Garden Boston MA Walk This Way
and I'm trying to print out a table listing all dates that have a 'Walk This Way' in the Song column, with the actual string 'Walk This Way.'
Any ideas why this isn't working?
Thanks a lot.
I'm trying out some php/mysql code for the first time, and I'm getting errors while trying some example code from www.w3schools.com.
Here is the page I'm looking at:
http://www.w3schools.com/php/php_mysql_select.asp
and here is the code I'm trying:
<?php
$con = mysql_connect("mysql1.***************","a2080062_mpr","test!!");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("stest", $con);
$result = mysql_query("SELECT * FROM stest2 WHERE Song='Walk This Way'");
echo "<table border='1'>
<tr>
<th>Date</th>
<th>Song</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Date'] . "</td>";
echo "<td>" . $row['Song'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
The error I get on my site says it's with the
while($row = mysql_fetch_array($result))
line, and it says:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a2080062/public_html/test.html on line 21
The table in the database I'm accessing has four columns: "Date," "Venue," "Location," "Song." So a row in this table might look like:
1975-04-19 Boston Garden Boston MA Walk This Way
and I'm trying to print out a table listing all dates that have a 'Walk This Way' in the Song column, with the actual string 'Walk This Way.'
Any ideas why this isn't working?
Thanks a lot.