Page 1 of 1

Unexpected T_VARIABLE

Posted: Mon Nov 30, 2009 2:34 am
by Ben11858
I received the follow error from my code...

Code: Select all

Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\Briefsystem\Accused.php on line 17
Line 17 is the follow...

Code: Select all

$updatesq = "UPDATE Accused SET firstname = \""$_POST['afname']"\", middlename = \""$_POST['amname']"\" WHERE briefcasen = \"" . $briefcasen . "\"";
I'm using this code on the submit of the form, to update my database from post data. The $briefcase number has been assigned earlier so that it updates the right record and updates the name details in that record, but I'm not sure why am getting this error. I have taken out the $briefcasen details I still get the same error.

Any ideas?

Re: Unexpected T_VARIABLE

Posted: Mon Nov 30, 2009 2:49 am
by Griven
Try this:

Code: Select all

$afname = mysql_real_escape_string($_POST['afname']);
$amname = mysql_real_escape_string($_POST['amname']);
 
$updatesq = "UPDATE Accused SET firstname = '$afname', middlename = '$amname' WHERE briefcasen = '$briefcasen'";
Always, without exception, sanitize all database inputs that come from the POST and GET arrays. This will protect you from SQL Injection.

In addition, when placing variables inside double quotes, you do not need to concatenate. See the code below for a working example.

Code: Select all

$myvar1 = 'foo';
$myvar2 = 'bar';
 
//Using double quotes, we can place variables directly into the string 
//without the use of concatenation
echo "The value of my two variables are $myvar1 and $myvar2";
 
//Alternatively, if we use single quotes, we are required to concatenate
echo 'The value of my two variables are ', $myvar1 ,' and ', $myvar2;
Also take note of my use of commas rather than periods when concatenating the string with single quotes. Commas offer a moderate performance boost over periods in this case.

Re: Unexpected T_VARIABLE

Posted: Mon Nov 30, 2009 3:48 am
by Ben11858
Thanks mate, your a legend. That worked beautifully...

I dunno if someone can help me with this one, but is there a way to join variables into 1 variable with addition text.. Like for example..

Code: Select all

 
$num1 = 1
$num2 = 2
$num3 = 3
$totalnum = $num1,$num2,num3;
echo $totalnum
 
So that end result is '1,2,3' when echo is done..

Re: Unexpected T_VARIABLE

Posted: Mon Nov 30, 2009 3:53 am
by Grizzzzzzzzzz
yes there is, although its something very basic so it would probably be better for you to learn the concept behind it,

the answer is in this post

viewtopic.php?f=1&t=109492

don't be like the other guy we tried to teach it to :P

Re: Unexpected T_VARIABLE

Posted: Mon Nov 30, 2009 4:35 am
by Ben11858
Awesome, that worked just perfectly... Got it all joined together like i needed, pretty simple really... Thanks mate its helping me out heaps guys..