phppup Posted March 27, 2019 Share Posted March 27, 2019 I am updating some old code to the IMPROVED version of PHP and running into a problem in this section after connecting successfully to my database: // retrieve the record that was selected $record_id = (isset($_POST['record_id'])) ? $_POST['record_id'] : ''; //check for $record_id emptiness if(!empty($record_id)){ // Retrieve ALL the data from the "example" table $result = mysqli_query($conn, "SELECT * FROM $table WHERE id = $record_id ") or die(mysqli_error()); // store the record of the "example" table into $row $row = mysqli_fetch_array( $result, MYSQLI_BOTH ); } Not sure what I'm missing or what needs to be re-organized. Please advise. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 27, 2019 Share Posted March 27, 2019 9 minutes ago, phppup said: and running into a problem Do you care to share with us what problem you are having? Are you getting an error message? Quote Link to comment Share on other sites More sharing options...
phppup Posted March 27, 2019 Author Share Posted March 27, 2019 I have many BLANK lines for easier reading in my coding. My first ERROR MESSAGE read: Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/..... on line 368 So, I commented out line 368 $result = mysqli_query($conn, "SELECT * FROM $table WHERE id = $record_id "); //or die(mysqli_error()); This took me to the following: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/.... on line 378 $row = mysqli_fetch_array( $result, MYSQLI_BOTH ); which is required to fill fields with data from my table. I guess I need to fix the fetch and the mysqli_error for a fully acceptable coding result. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 27, 2019 Share Posted March 27, 2019 1 minute ago, phppup said: Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/..... on line 368 Then provide the parameter it needs. The contents of that message you have commented out should tell you what is wrong. Quote Link to comment Share on other sites More sharing options...
phppup Posted March 27, 2019 Author Share Posted March 27, 2019 It is rather unfair of you to force me to think so decisively. I was doubting my code, rather than simply verifying the easy (and stupid) mistakes. I got it now. Thank you, as always. Quote Link to comment Share on other sites More sharing options...
phppup Posted March 27, 2019 Author Share Posted March 27, 2019 (edited) Now that I'm playing with ERROR messages, I see that or die(mysqli_error()) provides the line number that corresponds to the coding issue, but differs from or die(mysqli_error($conn)) which specifically gave me a reason for the unsuccessful effort. Is there a simple way to display BOTH pieces of information, or does an IF statement need to be created? Edited March 27, 2019 by phppup Quote Link to comment Share on other sites More sharing options...
Barand Posted March 27, 2019 Share Posted March 27, 2019 10 minutes ago, phppup said: Is there a simple way to display BOTH pieces of information The former had a php error so gave you a php error message. The latter gives you the mysql error message. If you see the first then you won't see the second (as you found out). However the latter should tell the line number in your code where the mysql error occured. A couple of pieces of advice. 1 ) If you are moving off mysql_ functions, move to PDO and not mysqli_ functions. 2 ) If you insist on sticking with mysqli, call mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); before your mysqli connection code. That will tell mysqli to automatically report all errors without your having to use "or die()" every time. 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.