nielcleo Posted October 4, 2011 Share Posted October 4, 2011 Hi, Anyone here please help me viewing the database table content.. i have only the infodatabase name, table name, user and password of the database.. i tried to use this <?php$con = mysql_connect("localhost,"user","password");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("mydb", $con);$result = mysql_query("SELECT * FROM char ORDER BY DESC");while($row = mysql_fetch_array($result)){echo "<table border='1' width='100%'><tr>";echo "<td>" .$row['char_id']. "</td>";echo "<td>" .$row['name']. "</td>";echo "<td>" .$row['str']. "</td>";echo "<td>" .$row['agi']. "</td>";echo "<td>" .$row['max_hp']. "</td>";echo "<td>" .$row['hp']. "</td>";echo "</tr></table>";}?> but it has an error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/nielcle1/public_html/haha.php on line 12 here the code in line 12while($row = mysql_fetch_array($result)) please anyone help me Link to comment Share on other sites More sharing options...
justsomeguy Posted October 4, 2011 Share Posted October 4, 2011 There's an error with your query. You need to check for those errors yourself if mysql_query returns false. $result = mysql_query("SELECT * FROM char ORDER BY DESC") or exit(mysql_error()); Link to comment Share on other sites More sharing options...
Ingolme Posted October 4, 2011 Share Posted October 4, 2011 The query is wrong. The mistake is actually on this line: $result = mysql_query("SELECT * FROM char ORDER BY DESC"); Most likely, the table "char" doesn't exist, or you haven't selected a database.To test for errors, check that $result isn't false. If it is, then check mysql_error(). if(!$result) { echo mysql_error(); exit;} Link to comment Share on other sites More sharing options...
nielcleo Posted October 5, 2011 Author Share Posted October 5, 2011 i encounter this errorYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'char' at line 1 im sure that char table is existing Link to comment Share on other sites More sharing options...
chitchirya Posted October 5, 2011 Share Posted October 5, 2011 $result = mysql_query("SELECT * FROM char ORDER BY DESC"); How do you order your selection? ORDER BY? Link to comment Share on other sites More sharing options...
nielcleo Posted October 5, 2011 Author Share Posted October 5, 2011 its fine if i will remove the ORDER BY.. my problem is the result is not displaying on selected table Link to comment Share on other sites More sharing options...
Ingolme Posted October 5, 2011 Share Posted October 5, 2011 char is a reserved word, escape it like this:SELECT * FROM `char` Link to comment Share on other sites More sharing options...
nielcleo Posted October 5, 2011 Author Share Posted October 5, 2011 thanks its work fine Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.