Page 1 of 1

inserts not working

Posted: Wed May 25, 2011 8:58 am
by ramblin54321
I've tried '$variable', '.$variable.', ' " .$variable. " ', Maybe I'm just tired after so many hours but I can't see why my last two INSERT INTO are not working. Someone please help. Thanks.

Code: Select all

$entries = "INSERT INTO allowances (totalGrossPay) VALUES ('$totalGrossPay') WHERE SSN = '".$SSN."'";
	mysql_query ($entries);
	
	$SQL = "INSERT INTO ".$tableName." (SSN, Last, First, payRate, grossPay, status, fedAllowance, stateAllowance, fedExtra, stateExtra, stateEstimated, fedTax, SS, Med, stateTax,
	garnishment, FUTA, CalUI, ETT, SDI, employerSS) VALUES ('$SSN', '$Last', '$First', '$payRate', '$grossPay', '$status', '$fedAllowance', '$stateAllowance', '$fedExtra',
	'$stateExtra', '$stateEstimated', '$fedTax', '$SS', '$Med', '$stateTax', '$garnishment', '$FUTA', '$CalUI', '$ETT', '$SDI, '$employerSS')";
	mysql_query ($SQL);	

Re: inserts not working

Posted: Wed May 25, 2011 9:54 am
by Weirdan
here's your error - you missed closing quote after $SDI:
'$SDI, '$employerSS'
Btw, it would have been easier for you to notice it if you used INSERT INTO ... SET column1='value', column2='value2', ... syntax and added linebreaks:

Code: Select all

$sql = <<<SQL
INSERT INTO {$tableName}
SET
   SSN            = '{$SSN}',
   Last           = '{$Last}',
   First          = '{$First}',
   payRate        = '{$payRate}',
   grossPay       = '{$grossPay}',
   status         = '{$status}',
   fedAllowance   = '{$fedAllowance}',ยท
   stateAllowance = '{$stateAllowance}',
   fedExtra       = '{$fedExtra}',
   stateExtra     = '{$stateExtra}',
   stateEstimated = '{$stateEstimated}',
   fedTax         = '{$fedTax}',
   SS             = '{$SS}',
   Med            = '{$Med}',
   stateTax       = '{$stateTax}',
   garnishment    = '{$garnishment}',
   FUTA           = '{$FUTA}',
   CalUI          = '{$CalUI}',
   ETT            = '{$ETT}',
   SDI            = '{$SDI}',
   employerSS     = '{$employerSS}'
SQL;

Re: inserts not working

Posted: Wed May 25, 2011 8:22 pm
by ramblin54321
Hi Weirdan,
I see you are from Odessa, Ukraine. I've been there once. Some of the most beautiful ladies in the world! Thanks for the help. Do you see anything wrong with the first insert statement? It is not working.

Re: inserts not working

Posted: Thu May 26, 2011 6:49 am
by Weirdan
add some error handling to see the error you're getting. In its simplest form it would be something like this:

Code: Select all

mysql_query(....) or die(mysql_error());