# [SOLVED] php/mysql unknown column in field list



## lotusweb

this code keeps returning with 
"unknown column '$first_name' in 'field list'

can someone tell me why?

$insert = 'INSERT INTO survey (first_name, last_name, year_of_birth, personalities, bedtime, wake_time, hrs_harrassing, hrs_therapy, hrs_counting_meds, hrs_dr_phil, hrs_joking)
VALUES ($first_name, $last_name, $year_of_birth, $personalities, $bedtime, $wake_time, $hrs_harrassing, $hrs_therapy, $hrs_counting_meds, $hrs_dr_phil, $hrs_joking)';
$success = mysql_query($insert); 

cheers
kerri:upset:


----------



## carsey

*Re: php/mysql unknown column in field list*



PHP:


$insert = 'INSERT INTO survey (first_name, last_name, year_of_birth, personalities, bedtime, wake_time, hrs_harrassing, hrs_therapy, hrs_counting_meds, hrs_dr_phil, hrs_joking)
VALUES ('$first_name', '$last_name','$year_of_birth', '$personalities', '$bedtime', '$wake_time', '$hrs_harrassing', '$hrs_therapy', '$hrs_counting_meds', '$hrs_dr_phil', '$hrs_joking')';
$success = mysql_query($insert);

Try that.


----------



## lotusweb

*Re: php/mysql unknown column in field list*

thanks carsey,

all good now


----------



## carsey

Glad you got it fixed :smile:


----------



## doozie

I've been trying to edit component in Joomla...but i got this error message Column count doesn't match value count at row 1 SQL=INSERT INTO jos_sv_res_request(name, passport_number, unit_number, phone, email, resource, startdate, starttime, enddate, endtime, comment ,user_field1_value ,user_field2_value ) VALUES('Mila Alan','3','0179872345','[email protected]','2','2009-7-23','14:00','2009-7-25','19:00','','Checked','Checked') ...after add a new column in a field...can somebody help me..



$sSql = "INSERT INTO #__sv_res_request(".
"name, ".
"unit_number, ".
"phone, ".
"email, ".
"resource, ".
"startdate, ".
"starttime, ".
"enddate, ".
"endtime, ".
"comment ";
if($_POST['user_field1_value'] != ""){
$sSql = $sSql.",user_field1_value ";
} 
if($_POST['user_field2_value'] != ""){
$sSql = $sSql.",user_field2_value ";
} 
if($_POST['user_field3_value'] != ""){
$sSql = $sSql.",user_field3_value ";
} 
if($_POST['user_field4_value'] != ""){
$sSql = $sSql.",user_field4_value ";
} 
$sSql = $sSql.") VALUES(".
"'".$name."',".
"'".$passport_number."',".
"'".$unit_number."',".
"'".$phone."',".
"'".$email."',".
"'".$resource."',".
"'".$startdate."',".
"'".$starttime."',".
"'".$enddate."',".
"'".$endtime."',".
"'".$comment."'";
if($_POST['user_field1_value'] != ""){
$sSql = $sSql.",'".$_POST['user_field1_value']."'";
} 
if($_POST['user_field2_value'] != ""){
$sSql = $sSql.",'".$_POST['user_field2_value']."'";
} 
if($_POST['user_field3_value'] != ""){
$sSql = $sSql.",'".$_POST['user_field3_value']."'";
} 
if($_POST['user_field4_value'] != ""){
$sSql = $sSql.",'".$_POST['user_field4_value']."'";
} 

$sSql = $sSql.")";
$database->setQuery($sSql);


----------

