inserts not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ramblin54321
Forum Commoner
Posts: 32
Joined: Wed Nov 18, 2009 5:31 am

inserts not working

Post 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);	
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: inserts not working

Post 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;
ramblin54321
Forum Commoner
Posts: 32
Joined: Wed Nov 18, 2009 5:31 am

Re: inserts not working

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: inserts not working

Post 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());
Post Reply