By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

php getting row from database using users id

P: 4
im getting a issue where $ variables are getting ignored and do not know why here is the error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

here is the code
Expand|Select|Wrap|Line Numbers
  1. <center>
  2. <title>J~Net Balance Accounts</title>
  3. <?php
  4. // Connects to your Database
  5. mysql_connect("localhost", "root", "password") or die(mysql_error());
  6. mysql_select_db("messages") or die(mysql_error());
  7. $data = mysql_query("SELECT * FROM users where id = $id")
  8. or die(mysql_error());
  9. Print "<table border cellpadding=3>";
  10. while($info = mysql_fetch_array( $data ))
  11. {
  12. Print "<tr>";
  13. Print "<th>User:</th> <td>".$info['user_name'] . "</td> ";
  14. Print "<th>Balance:</th> <td>".$info['balance'] . " </td></tr>";
  15. }
  16. Print "</table>";
  17. ?> 

any ideas please anyone as it might be something silly
Oct 14 '11 #1
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,350
I don't see where $id is defined or initialized anywhere.
Oct 14 '11 #2

NeoPa
Expert Mod 15k+
P: 31,349
Please check When Posting (VBA or SQL) Code. This applies to you as you're asking about SQL but only posting your PHP code.

Nevertheless, your problem is in line #7, as you'd see easily if you'd posted the SQL itself.
Oct 14 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.