-5

I know, there are tons of other topics about this but none match what I need help with. I'm trying to make a user profile system and it gives me the error in the title. Here is my cod:

<?php
$dbname="users";
$host="localhost";
$user="root";
$pass="";

$link = mysql_connect($host, $user, $pass);
mysql_select_db($dbname, $link);



$sql_statement = 'SELECT username, name, aboutme, website FROM userprofile';
$result = mysql_query($sql_statement, $link);

while($row = mysql_fetch_array($result))
  {
  echo "<b>User:</b> ".$row['username'].'<br>';
  }
?>
  • Did none of the other duplicates suggest using `mysql_error()` to actually find out what's wrong? – mario Apr 13 '13 at 21:25
  • 2
    **The `mysql_` functions have been depreciated. Please refrain from using them in new code.** – Matt Clark Apr 13 '13 at 21:25
  • Change line 13 to the following, and then post the results: `$result = mysql_query($sql_statement, $link) or die(mysql_error());` – Matt Clark Apr 13 '13 at 21:36
  • Just because the other dupes are using different queries doesn't mean they don't apply to your problem: One of your database operations has failed, your code is blindly (and stupidly) assuming nothing could possibly ever go wrong, and now you're paying the price. **ALWAYS** check for success/failure when dealing with external resources. This a kazillion times more applicable while debugging/developing too. – Marc B Apr 13 '13 at 21:53

1 Answers1

0

Usually when this happens and the passed variable is clearly a result resource, as shown here, you have a MySQL syntax problem.

Try executing that query from the MySQL command line. It will likely complain about syntax, or an unknown column or table. Very, very carefully look at the column names in your query and check that they exactly match what's in the database.

Alternatively, depending on your error level, you might not even be connecting to the database. The code you have is fine, the problem exists in the transaction between SQL and PHP.

JRL
  • 830
  • 6
  • 18