This topic is locked

Insert Into

9/11/2013 11:57:29 PM
PHPRunner General questions
R
RTC author

Hello All,
I am just not understanding the Insert Into code after reviewing several sites.
I have two tables Timesheet and Billings with Project and Client as varchars, Date as Date and Quantity as an Interger. I am wanting to insert into Billings before the record is added. I added the following code:
global $conn;

$strSQLInsert = "insert into Billings (Client, Project, Date, Quantity) values ('$Client','$Project','$Date',$Quantity);"

db_exec($strSQLInsert,$conn);
and receiving error " Parse error: syntax error, unexpected T_STRING in /home/content/13/10797013/html/vector/vector/include/Timesheet_events.php on line 36"
Thanks

C
cgphp 9/12/2013
global $conn;

$strSQLInsert = "insert into Billings (Client, Project, Date, Quantity) values ('".$Client."','".$Project."','".$Date."',".$Quantity.");"

db_exec($strSQLInsert,$conn);


If $Client, $Project, $Date and $Quantity are variables linked to the add form fields, use the $values array to access them (for example $values['Client']). Check this article http://xlinesoft.com/phprunner/docs/before_record_added.htm

R
RTC author 9/13/2013

Hi Cristian, I appreciate your reply.
I updated the event and it still did not work. I received the following error:
Error type 256

Error description You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

URL ..../Timesheet_add.php?ferror=1&

Error file /home/content/13/10797013/html/vector/vector/include/dbconnection.my.mysqli.php

Error line 42

SQL query insert into Billings (Client, Project, Date, Quantity) values ('','','',);


global $conn;

$strSQLInsert = "insert into Billings (Client, Project, Date, Quantity) values ('".$Client."','".$Project."','".$Date."',".$Quantity.");"

db_exec($strSQLInsert,$conn);


If $Client, $Project, $Date and $Quantity are variables linked to the add form fields, use the $values array to access them (for example $values['Client']). Check this article http://xlinesoft.com/phprunner/docs/before_record_added.htm

C
cgphp 9/13/2013

As I told you above, if the $Client, $Project, $Date and $Quantity variables are linked to the add form fields you have to use the $values array to access them.

Sergey Kornilov admin 9/13/2013

Something like this:

global $conn;

$strSQLInsert = "insert into Billings (Client, Project, Date, Quantity) values ('".$values["client"]."','".$values["project"]."','".$values["date"]."',".$values["quantity"].");"

db_exec($strSQLInsert,$conn);