So I am a newb to php & mysql. I keep getting this error each time I fill out a form that I created. When I check phpmyadmin to see if the information from the form has been added to the table, it's nowhere to be found. I found a similar question on here and their problem was fixed by running a query to turn the strict mode off of SQL. I tried to do so and it added an entry to the table but all the values in the entry were 0. Here's my php block:
<?php
require('connect2.php');
session_start();
$username = $_SESSION['username'];
//My queries will be here
$bloodquery = mysql_query("SELECT * FROM `CodesBloodType` ORDER BY `BloodTypeText`");
$donor_add = "INSERT INTO `Donor`(`DonorID`, `PersonID`, `DateRegistered`, `AgeRegistered`, `DonorPreRegistered`, `MedicalFacilityID`, `NationalLocalRegistry`, `NationalLocalRegistryID`, `Height`, `Weight`, `BloodTypeCode`, `OrganCriteriaID`, `LivingDonor`, `DirectedDonor`) VALUES ($donorid,$personid,$dateregistered,$ageregistered,$donorpreregistered,$medicalfacilityid,$nationallocalregistry,$nationallocalregistryid,$height,$weight,$bloodtypecode,$organcriteriaid,$livingdonor,$directeddonor)";
//Check to see if something is entered in my fields, if so then define variables
// Loop over field names, make sure each one exists and is not empty
$required = array('donorid', 'personid', 'dateregistered', 'ageregistered','medicalfacilityid','nationallocalregistry','nationallocalregistryid', 'height', 'weight','organcriteriaid');
$error = false;
$var = $_POST['submit'];
if($var){
foreach($required as $field) {
if (empty($_POST[$field])) {
$error = true;
if ($error) {
echo $field. ' is empty';
?>
<html><br></html>
<?php
}
}
else{
$error = false;
}
}
if(!$error){
$donorid = $_POST['donorid'];
$personid = $_POST['personid'];
$dateregistered = $_POST['dateregistered'];
$ageregistered = $_POST['ageregistered'];
if(isset($_POST['donorpreregistered'])){
$donorpreregistered = "1";}
else{
$donorpreregistered = "0";
}
$medicalfacilityid = $_POST['medicalfacilityid'];
$nationallocalregistry = $_POST['nationallocalregistry'];
$nationallocalregistryid = $_POST['nationallocalregistryid'];
$height = $_POST['height'];
$weight = $_POST['weight'];
$bloodtypecode = $_POST['bloodtypec'];
$organcriteriaid = $_POST['organcriteriaid'];
if(isset($_POST['livingdonor']))
{
$livingdonor = "1";
}
else{
$livingdonor = "0";
}
if(isset($_POST['directeddonor'])){
$directeddonor = "1";}
else{
$directeddonor = "0";
}
$result = mysql_query($donor_add);
if (!$result) {
die('Invalid query: ' . mysql_error());
//echo "Form Submitted Successfully";
}
}
}
?>
Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',,,,,,,,,,,,)' at line 1