Cannot figure out PHP portion of SQL Update for a date

I've got a SQL DB in Azure. I am running the Webapps PHP link to that DB.

I can connect fine, and retrieve data. I am having troubles trying to update a table.

My SQL statement is:

$sql3="UPDATE EmpBonus SET EmpBonus_BonusAmt=?, EmpBonus_StartDate=?, EmpBonus_EndDate=?, EmpBonus_Current=? WHERE Id=?";

I can pass the parameters over via this line of code

$params=array($bonusamt,$startdate,$enddate,$currentstr,$primkey);

My problem is that the DATES $startdate or $enddate have to have the single quote around the date i.e. '2015-01-01' or else SQL will reject it.

I can't find on the web where I can insert the single quote around the date in PHP.

Can anyone help?

June 19th, 2015 8:51am

Hi Jeff,

Is there a reason why you can't put single quotes around question mark? Like this:

$sql3="UPDATE EmpBonus SET EmpBonus_BonusAmt=?, EmpBonus_StartDate='?', EmpBonus_EndDate='?', EmpBonus_Current=? WHERE Id=?";

Thanks,
Veljko

Free Windows Admin Tool Kit Click here and download it now
June 19th, 2015 9:21am

I did try it, but it still doesn't work.

Is there a way to see what the actual SQL statement looks like?

$stmt3=sqlsrv_query($conn,$sql3,$params)

My array gives these values

Array (    [0] => 50000    [1] => 2015-01-01    [2] => 2016-12-31    [3] => 1    [4] => 1 )

When I type in those values into the SQL console, the only thing stopping it from updating is the missing ' ' from the dates.

I assume that where my problem lies?

June 19th, 2015 3:02pm

I did try it, but it still doesn't work.

Is there a way to see what the actual SQL statement looks like?

$stmt3=sqlsrv_query($conn,$sql3,$params)

My array gives these values

Array (    [0] => 50000    [1] => 2015-01-01    [2] => 2016-12-31    [3] => 1    [4] => 1 )

When I type in those values into the SQL console, the only thing stopping it from updating is the missing ' ' from the dates.

I assume that where my problem lies?

Free Windows Admin Tool Kit Click here and download it now
June 19th, 2015 6:55pm

I did try it, but it still doesn't work.

Is there a way to see what the actual SQL statement looks like?

$stmt3=sqlsrv_query($conn,$sql3,$params)

My array gives these values

Array (    [0] => 50000    [1] => 2015-01-01    [2] => 2016-12-31    [3] => 1    [4] => 1 )

When I type in those values into the SQL console, the only thing stopping it from updating is the missing ' ' from the dates.

I assume that where my problem lies?

June 19th, 2015 6:55pm

I did try it, but it still doesn't work.

Is there a way to see what the actual SQL statement looks like?

$stmt3=sqlsrv_query($conn,$sql3,$params)

My array gives these values

Array (    [0] => 50000    [1] => 2015-01-01    [2] => 2016-12-31    [3] => 1    [4] => 1 )

When I type in those values into the SQL console, the only thing stopping it from updating is the missing ' ' from the dates.

I assume that where my problem lies?

Free Windows Admin Tool Kit Click here and download it now
June 19th, 2015 6:55pm

Arrgh. It was my fault. I forgot to input the ID in the primary key. It wasn't the date at all.
July 1st, 2015 9:16pm

Arrgh. It was my fault. I forgot to input the ID in the primary key. It wasn't the date at all.
Free Windows Admin Tool Kit Click here and download it now
July 1st, 2015 9:16pm

Arrgh. It was my fault. I forgot to input the ID in the primary key. It wasn't the date at all.
July 2nd, 2015 1:16am

Arrgh. It was my fault. I forgot to input the ID in the primary key. It wasn't the date at all.
Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2015 1:16am

Arrgh. It was my fault. I forgot to input the ID in the primary key. It wasn't the date at all.
July 2nd, 2015 1:16am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics