cw2395 Posted November 24, 2014 Share Posted November 24, 2014 I keep getting this error Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in on line 21 <html><body><h1> Database </h1><?phpmysql_connect('localhost', 'cw2395', 'tNlkcI6k') or die(mysql_error());mysql_select_db('cw2395') or die (mysql_error());$reference = mysql_query("SELECT * FROM contacts");?><table border = "3" cellspacing = "3" cellpadding = "3"> <tr> <th> First Name </th> <th> Last Name </th> <th> Address </th> <th> State </th> <th> Zip </th> <th> Telephone </th> <th> Email </th> </tr><?php while($row = mysql_fetch_array($reference)) { THIS IS LINE 21 $cell1 = $row['Fname']; //Contacts first name $cell2 = $row['Lname']; //Contacts last name $cell3 = $row['Address']; //Contacts address $cell4 = $row['State']; //Contacts state of residence $cell5 = $row['Zip']; //Contacts zip code of residence $cell6 = $row['Phone']; //Contacts phone number $cell7 = $row['Email']; //Contacts email address?> help would be very appreciated Quote Link to comment https://forums.phpfreaks.com/topic/292688-keep-getting-same-error/ Share on other sites More sharing options...
mikosiko Posted November 24, 2014 Share Posted November 24, 2014 I keep getting this error Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in on line 21 means that your query is incorrect and hence failing. Add this lines after your <?php opening tag or better yet setup how to manage and display errors in your php.ini. It should give your indication of what is going on. // Define how to display/report errors ini_set("display_errors", "1"); error_reporting(-1); In additional note: - You should not be using mysql_ API it has been already deprecated; you should be using mysqli_ or PDO Quote Link to comment https://forums.phpfreaks.com/topic/292688-keep-getting-same-error/#findComment-1497542 Share on other sites More sharing options...
ginerjm Posted November 24, 2014 Share Posted November 24, 2014 1 - It means your query failed. Since you checked the connect and the select that means you probably specified the table name incorrectly in your query statement. 2 - You should cease and desist from using the MySQL_* functions. Period. Read the manual for any one of these functions and see why. Quote Link to comment https://forums.phpfreaks.com/topic/292688-keep-getting-same-error/#findComment-1497543 Share on other sites More sharing options...
Barand Posted November 24, 2014 Share Posted November 24, 2014 Then your query $reference = mysql_query("SELECT * FROM contacts"); has failed. Check to see what mysql_error() contains. NOTE: you should not be using mysql_ functions, they are deprecated. Use mysqli_ or PDO instead. Quote Link to comment https://forums.phpfreaks.com/topic/292688-keep-getting-same-error/#findComment-1497544 Share on other sites More sharing options...
cw2395 Posted November 24, 2014 Author Share Posted November 24, 2014 Its saying DatabaseTable 'cw2395.contacts' doesn't exist Im suppose to br creating basically a contact index that stores in a Database name, location, phone etc. I know I should be using mysqli, but this is the last assignment for the class and he has been using this the whole time Quote Link to comment https://forums.phpfreaks.com/topic/292688-keep-getting-same-error/#findComment-1497552 Share on other sites More sharing options...
ginerjm Posted November 24, 2014 Share Posted November 24, 2014 Like I said - the table name you used is wrong. Either you are in the wrong db for that table name or you are referencing the wrong table. Quote Link to comment https://forums.phpfreaks.com/topic/292688-keep-getting-same-error/#findComment-1497555 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.