CiszLaserna Posted February 3, 2013 Share Posted February 3, 2013 Kinda new to php im using array to post the inbox of an email application but it seems i got an error this code here: <?php $hostname = "localhost"; $password = "password"; $database = "reports"; $username = "your_name"; //connection to the database $con = mysql_connect($hostname, $username, $password) or die("Connecting to MySQL failed"); //select a database to work with $selected = mysql_select_db("report", $con) or die("Could not select examples"); //execute the SQL query and return records $result = mysql_query("SELECT id, stations, title, detail from insert"); //fetch tha data from the database while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "ID:".$row{'Id'}. "Station:".$row{'Stations'}. "Title:".$row{'Title'}. "Detail:".$row{'Detail'}."<br>"; } //close the connection mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 3, 2013 Share Posted February 3, 2013 You need to check for errors. See the link in my signature on debugging SQL. Quote Link to comment Share on other sites More sharing options...
CiszLaserna Posted February 3, 2013 Author Share Posted February 3, 2013 (edited) error is this Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\report\inbox.php on line 23 Edited February 3, 2013 by CiszLaserna Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 3, 2013 Share Posted February 3, 2013 You need to check for errors. See the link in my signature on debugging SQL. Quote Link to comment Share on other sites More sharing options...
Andy123 Posted February 3, 2013 Share Posted February 3, 2013 If I had a penny for every time someone asked about this error on this forums, I would be rich. I don't mean to be rude. The error message is actually very precise and helpful. mysql_fetch_array() is being called with a boolean value where a resource is expected. If you look at the documentation for mysql_query(), you will see that it returns FALSE on failure, which is a boolean. This value is stored in $result, which is then passed to mysql_fetch_array(). So, an error occurs with your SQL query. Perhaps you made a spelling mistake or perhaps the word "insert" is not allowed; I am actually not sure. Anyways, you can check the error like this: $result = mysql_query("SELECT id, stations, title, detail from insert") or die(mysql_error()); Also, please consider using MySQLi or PDO instead as the mysql_* extension is deprecated. I am merely name dropping here, so please take the time to read about these. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 3, 2013 Share Posted February 3, 2013 The problem is the use of "insert" but OP needs to learn to capture mysql errors. Quote Link to comment Share on other sites More sharing options...
CiszLaserna Posted February 3, 2013 Author Share Posted February 3, 2013 opps did na see. thank you 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.