lisovaccaro
lisovaccaro

Reputation: 33996

Cannot select from database?

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_query("SELECT * FROM Lines");
  while($row = mysql_fetch_array( $result )) ***************
  { 
  echo $row['Text'];
  echo "<br />";
  } 
  mysql_close($con);

What am I doing wrong? Thanks

Upvotes: 0

Views: 122

Answers (2)

Jacob
Jacob

Reputation: 43299

Lines is a reserved word in MySQL. Use backticks.

SELECT * FROM `Lines`

Upvotes: 4

Andreas Wong
Andreas Wong

Reputation: 60584

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);

Upvotes: 0

Related Questions