I'm trying to select from my MySQL database, from the table Lines. I made it really simple, it should simply show all rows in the database. However I'm getting an error on line 16 (I put an * next to it) that says: "mysql_fetch_array(): supplied argument is not a valid MySQL result resource"
$con = mysql_connect("...","...","mypass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);
$result = mysql_que开发者_StackOverflow社区ry("SELECT * FROM Lines");
while($row = mysql_fetch_array( $result )) ***************
{
echo $row['Text'];
echo "<br />";
}
mysql_close($con);
What am I doing wrong? Thanks
Lines is a reserved word in MySQL. Use backticks.
SELECT * FROM `Lines`
Add mysql_error() after mysql_query() to see if there's any error, I'm guessing table Lines doesn't exist:
$con = mysql_connect("copoetry.db.6945202.hostedresource.com","dbname","mypass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);
$result = mysql_query("SELECT * FROM Lines");
echo mysql_error(); die;
while($row = mysql_fetch_array( $result )) ***************
{
echo $row['Text'];
echo "<br />";
}
mysql_close($con);
精彩评论