Page 1 of 1

Stupid Syntax Error

Posted: Wed May 11, 2005 3:25 am
by Hengis
This is a really simple syntax error that I cant figure out and its driving me nuts!

What is the difference between

Code: Select all

$userid = $rї'fld_int_id'];
    $sql = &quote;INSERT into tbl_projPeop (fld_int_PersonID, fld_str_Project) Values ('$userid','P1234')&quote;;
AND

Code: Select all

$userid = $rї'fld_int_id'];
    $sql = &quote;INSERT into tbl_projPeop (fld_int_PersonID, fld_str_Project) Values&quote;;
    $sql = $sql + &quote;('$userid' ,'P1234')&quote;;
The first one runs correctly but the second snippet returns this error

Code: Select all

Warning: odbc_exec(): SQL error: їMicrosoft]їODBC SQL Server Driver]їSQL Server]Line 1: Incorrect syntax near '1'., SQL state 37000 in SQLExecDirect in C:\Inetpub\tikiwiki\iain\index2.php on line 26
Not my eyes it should be the same but I am still a bit green to PHP.

I need to split the line out so the next stage of development is running multiple lines into the insert via a loop.

TIA

Hengis

Posted: Wed May 11, 2005 3:34 am
by hongco
oopsi, :oopsi, my face's burning up. :oops:

Posted: Wed May 11, 2005 4:13 am
by Hengis
I didnt think that was a problem. Indeed after altering it gives the same error.

I think its something to do with the variable inserted in the string. Is there another longer way to do it? i.e. variables.[$userid] or something?

Thanks

Posted: Wed May 11, 2005 4:30 am
by hongco
sorry, apprently, i stayed up too late trying to learn some flash lolz
yah the parenthesis is ok.

change the plus sign to a dot (.) for concatenation.

Code: Select all

$sql = $sql."('$userid' ,'P1234')";
//or
$sql .= "('$userid' ,'P1234')";

Posted: Wed May 11, 2005 4:56 am
by Hengis
Ah thanks - that worked a treat. I guess the pages I saw on operators wernt up to date or I was reading the wrong bits - thanks again