Stupid Syntax Error

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
Hengis
Forum Newbie
Posts: 3
Joined: Wed May 11, 2005 3:14 am

Stupid Syntax Error

Post 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
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

oopsi, :oopsi, my face's burning up. :oops:
Last edited by hongco on Wed May 11, 2005 4:32 am, edited 2 times in total.
Hengis
Forum Newbie
Posts: 3
Joined: Wed May 11, 2005 3:14 am

Post 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
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post 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')";
Hengis
Forum Newbie
Posts: 3
Joined: Wed May 11, 2005 3:14 am

Post 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
Post Reply