Jump to content

Desperately Needing Help on PHP/mySQL Inserting Function


Recommended Posts

Hello all. I've spent the last two days trying to figure this out. I've gone over 40 different tutorials and I can't find out what is going wrong.

 

The issue: I'm trying to use a PHP function that I created to insert data into mySQL. For some reason it will only insert the first value and nothing else.

 

The code:

// Initialize the function and show it what we'll be passing

function addCondo($name, $address, $city, $state, $zip, $yearbuilt, $num1br, $num2br, $num3br, $num4br, $totalunits, $pools, $jacuzzis, $parkingcovered, $parkingassigned, $stores, $dining, $gym, $floors, $tennis, $golf, $conference, $privatebalcony, $shuffleboard, $ownerslounge, $elevators, $towers, $onthegulf, $onthebay, $taxes, $pets, $masterongulf, $owneroccupancy, $fireplace, $privategarages, $rentalincome) {

// Connect to the database using mysqli()	
$connection = dbConnect();

//The query
$result = $connection->query("INSERT INTO condo VALUES ('$name', '$address', '$city', '$state', '$zip', '$yearbuilt', '$num1br', '$num2br', '$num3br', '$num4br', '$totalunits', '$floors', '$towers', '$onthegulf', '$onthebay', '$taxes', '$pets', '$masterongulf', '$owneroccupancy', '$rentalincome', '$pools', '$jacuzzis', '$parkingcovered', '$parkingassigned', '$stores', '$dining', '$tennis', '$golf', '$conference', '$privatebalcony', '$shuffleboard', '$ownerslounge', '$elevators', '$fireplace', '$privategarages', '$gym')");

// Check if it returns true
if (!$result) {
throw new Exception("Could not add condo to the database. ");
} else {
return true;
}

// Free memory and close connection
$result->free_results();
$connection->close();

}

 

I have the query set to insert in the order the fields are in mySQL, but for some reason, it only inserts the first field ($name).

Generally you troubleshoot missing data values by starting where the data is produced and determine at what point it no longer exists. Have you checked if your form (the first step) is even submitting the data to the form processing code?

 

There may be nothing functionally wrong with the code you posted (the last step.) The garbage you are getting out might in fact be due to feeding garbage in, though your validation logic in the the form processing code should be checking each piece of data to make sure it is what is expected before you attempt to put it into a query.

Thank you so much. I can't believe I didn't even think about checking the form. Figured it was all good considering that was the easiest part. I was missing one letter. Again, I can't tell you how much I appreciate it. I probably would have never ever went there.

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.