tsteuwer Posted February 21, 2010 Share Posted February 21, 2010 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). Quote Link to comment https://forums.phpfreaks.com/topic/192814-desperately-needing-help-on-phpmysql-inserting-function/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 21, 2010 Share Posted February 21, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/192814-desperately-needing-help-on-phpmysql-inserting-function/#findComment-1015663 Share on other sites More sharing options...
tsteuwer Posted February 21, 2010 Author Share Posted February 21, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/192814-desperately-needing-help-on-phpmysql-inserting-function/#findComment-1015772 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.