Hey guys,
This is driving me crazy. I am writing a loop that means the application is scalable. To do that I am making it so a loop will write the DB. I am getting an error below
PHP Code:
Unknown column 'sex' in 'field list'
The loop that creates the query is
PHP Code:
<?php // START UPDATE FORM
//Get the fields to update via query
$all_output1=""; //set variable so it doesnt force "NOTICE" in loop
$all_output2=""; //set variable so it doesnt force "NOTICE" in loop
if (isset($_POST['submit'])) {
$result = mysql_query("SELECT field_name FROM child_fields WHERE editible='1'") or die(mysql_error());
while($row = mysql_fetch_array($result)){
$safe_variable = make_safe($_POST[$row['field_name']]);
// Check for null
if (empty($safe_variable)) {
$output1 = $row['field_name'].", ";
$output2 = "'', ";
} else {
$output1 = $row['field_name'].", ";
$output2 = "'".$safe_variable."', ";
}
$all_output1 .= $output1;
$all_output2 .= $output2;
}
//trim last comma and space
$all_output1 = substr($all_output1,0,-2);
$all_output2 = substr($all_output2,0,-2);
echo $all_output1."<br>".$all_output2;
I have added the echo to view the output of each, and that looks correct
PHP Code:
first_name, last_name, dob, sex, ethnicity, school, class, medical, doctor, doctor_practice, doctors_phone, swim_ability
'', '', '', 'female', '', '', '122', 'Peanuts', '', '', '', ''
The fields are null due to testing what will happen if the user doesnt enter information, I want the program to continue not have an sql error.
'sex' is definitely a column. The actual sql query is
Code:
$query = "INSERT INTO caregiver ($all_output1) VALUES ($all_output2)";
I am lost as it appears from the echo that if I place that code in "()" as I have for the query it should run!? Any ideas people?? PS Have tried pasting the code into brackets straight into phpmyadmin and it works!?