Jump to content

MySqli Insert not working


ndjustin20
Go to solution Solved by mac_gyver,

Recommended Posts

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

Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.