logitechcam Posted February 14, 2007 Share Posted February 14, 2007 Hi, there I need help with the selection code. the following code has no error, but i just cannot select anything from the mysql. Connection is good, I donot know why i cannot select from the table. Plz Help! <?php $con = mysql_connect("localhost","root","*****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mysql", $con); $result = mysql_query("SELECT * FROM usres"); while($row = mysql_fetch_array($result)) { echo $row['Name'] . " " . $row['password']; echo "<br />"; }mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
papaface Posted February 14, 2007 Share Posted February 14, 2007 Are you sure "mysql" is the database's name? Quote Link to comment Share on other sites More sharing options...
logitechcam Posted February 14, 2007 Author Share Posted February 14, 2007 Are you sure "mysql" is the database's name? Yes, i am sure Quote Link to comment Share on other sites More sharing options...
papaface Posted February 14, 2007 Share Posted February 14, 2007 try this: <?php $con = mysql_connect("localhost","root","*****") or die('Could not connect: ' . mysql_error()); mysql_select_db("mysql", $con); $result = mysql_query("SELECT * FROM usres"); while($row = mysql_fetch_array($result)) { echo $row['Name'] . " " . $row['password']; echo ""; } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
logitechcam Posted February 14, 2007 Author Share Posted February 14, 2007 I tried your code, it still doesnot work. Thank you try this: <?php $con = mysql_connect("localhost","root","*****") or die('Could not connect: ' . mysql_error()); mysql_select_db("mysql", $con); $result = mysql_query("SELECT * FROM usres"); while($row = mysql_fetch_array($result)) { echo $row['Name'] . " " . $row['password']; echo ""; } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
papaface Posted February 14, 2007 Share Posted February 14, 2007 Try this and tell us the error you get: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $con = mysql_connect("localhost","root","*****") or die('Could not connect: ' . mysql_error()); mysql_select_db("mysql", $con); $result = mysql_query("SELECT * FROM usres"); while($row = mysql_fetch_array($result)) { echo $row['Name'] . " " . $row['password']; echo ""; } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 14, 2007 Share Posted February 14, 2007 Its not supposed to be "users" by any chance, is it? $result = mysql_query("SELECT * FROM users"); Quote Link to comment Share on other sites More sharing options...
logitechcam Posted February 14, 2007 Author Share Posted February 14, 2007 There is no error now, Thank you ,PapaFace Try this and tell us the error you get: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $con = mysql_connect("localhost","root","*****") or die('Could not connect: ' . mysql_error()); mysql_select_db("mysql", $con); $result = mysql_query("SELECT * FROM usres"); while($row = mysql_fetch_array($result)) { echo $row['Name'] . " " . $row['password']; echo ""; } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
o3d Posted February 14, 2007 Share Posted February 14, 2007 mysql is the system database, and one of the system tables in that database is 'user'. Just try the query "select * from user" to see if the problem still exists. Its not supposed to be "users" by any chance, is it? $result = mysql_query("SELECT * FROM users"); Quote Link to comment Share on other sites More sharing options...
logitechcam Posted February 14, 2007 Author Share Posted February 14, 2007 I created a table in mysql Database which is named users. mysql is the system database, and one of the system tables in that database is 'user'. Just try the query "select * from user" to see if the problem still exists. Its not supposed to be "users" by any chance, is it? $result = mysql_query("SELECT * FROM users"); Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 14, 2007 Share Posted February 14, 2007 You have a typo then, I believe. Currently it is: $result = mysql_query("SELECT * FROM usres"); and it should be: $result = mysql_query("SELECT * FROM users"); Quote Link to comment Share on other sites More sharing options...
logitechcam Posted February 14, 2007 Author Share Posted February 14, 2007 yes, you are right. Thank you to all u guys. One more question, what is the "ini_set('display_errors', '1');" for? You have a typo then, I believe. Currently it is: $result = mysql_query("SELECT * FROM usres"); and it should be: $result = mysql_query("SELECT * FROM users"); Quote Link to comment Share on other sites More sharing options...
papaface Posted February 14, 2007 Share Posted February 14, 2007 It displays any errors that occur. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.