ndjustin20 Posted September 5, 2013 Share Posted September 5, 2013 Hello, I am not able to get the following code to insert. Any help is much appreciated. This is my first whack at MySqli and there are no errors being thrown. The fields in the DB are varchar and the variables do have values. I've attached the file I am working on. In the php file it's lines 22 through 48 that I am trying to resolve currently. if(!empty($firstName) && !empty($lastName) && !empty($cell)){ $sql = "SELECT * FROM clientInformation WHERE firstName = '$firstName' AND lastName = '$lastName' AND cell = '$cell' LIMIT 1;"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); }else{ $numRows = $result->num_rows; } if($numRows > 0){ $newResult = $result->fetch_assoc(); }else{ $sql = "INSERT INTO clientInformation (firstName, lastName, address, city, zip, phone, cell, state, email) VALUES ('$firstName', '$lastName', '$address', '$city', '$zip', '$phone', '$cell', '$state', '$email');"; if(!$result = $con->query($sql)){ die('There was an error running the query [' . $con->error . ']'); } } } catchPDF.php Quote Link to comment https://forums.phpfreaks.com/topic/281893-mysqli-insert-not-working/ Share on other sites More sharing options...
Solution mac_gyver Posted September 5, 2013 Solution Share Posted September 5, 2013 your code is using mysql_real_escape string() and mysqli query statements. since it's unlikely that your code is making both a mysql and mysqli database connection, it's likely the mysql_real_escape_string functions are failing, which would be producing a number of php erors, and returning a null/false value. in this case, your select query would match zero rows and your logic is skipping over the insert query. please set php's error_reporting to E_ALL and display_errors to ON to get php to report and display all the errors it detects. Quote Link to comment https://forums.phpfreaks.com/topic/281893-mysqli-insert-not-working/#findComment-1448322 Share on other sites More sharing options...
ndjustin20 Posted September 5, 2013 Author Share Posted September 5, 2013 Thank you for the advice....I never even thought about the MySQL_real_escape_string being the issue. I'll turn on error reporting as I had forgot to when I started this little project. Thank you again as this was the problem :happy-04: Quote Link to comment https://forums.phpfreaks.com/topic/281893-mysqli-insert-not-working/#findComment-1448326 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.