Getting Error in Query String

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
User avatar
snowrhythm
Forum Commoner
Posts: 75
Joined: Thu May 04, 2006 1:14 pm
Location: North Bay Area, CA

Getting Error in Query String

Post by snowrhythm »

i've got a problem with this query string...

Code: Select all

<?php    

$sqlCommand = "INSERT INTO MachineServiceProfiles (MachineServiceProfileID, Model, SerialNumber, DateMade, DateShipped, WarantyExpireDate, LocationID, CompanyID) VALUES ($machineID, '$machineName', '$serialNum', 'Format(#$dateM#, 'Short Date')', Format(#$dateS#, 'Short Date'), Format(#$dateW#, 'Short Date'), $locationID, $companyID)";  

?>
when i go to execute the string i get this syntax error:

"Syntax error (missing operator) in query expression ''Format(#06/25/2003#, 'Short Date')''., SQL state 37000 in SQLExecDirect"

The weird thing about it is that 'Format(#06/25/2003#, 'Short Date')' works perfectly fine somewhere else in the same file, on the same table.
the only difference is that in the other place where it works i'm only change data, and here i'm adding a new row of data.
any ideas as to what the missing operator is?

thanks
User avatar
$phpNut
Forum Commoner
Posts: 40
Joined: Tue May 09, 2006 5:13 pm

Post by $phpNut »

I think it is trying to literally send 'Format(...)' to the database.

Try:

Code: Select all

<?php   

$sqlCommand = "INSERT INTO MachineServiceProfiles (MachineServiceProfileID, Model, SerialNumber, DateMade, DateShipped, WarantyExpireDate, LocationID, CompanyID) VALUES ($machineID, '$machineName', '$serialNum', " . Format($dateM, 'Short Date') . ", " . Format($dateS, 'Short Date') . ", " . Format($dateW, 'Short Date') . ", $locationID, $companyID)"; 

?>
Might be best to format the dates to a variables and then put the variables in the $sqlCommand string, less messy.
User avatar
snowrhythm
Forum Commoner
Posts: 75
Joined: Thu May 04, 2006 1:14 pm
Location: North Bay Area, CA

Post by snowrhythm »

hey thanks...i'm back at work now (on a saturday) and i'll try that. i'll let you know what happens.
Post Reply