Syntax error, unexpected t_variable. – PHP

  php

Q(Question):

hi.i have got a problem.

error message:

Parse error: syntax error, unexpected T_VARIABLE in c:\wamp\www\dynamic2.php on line 12

for the line:

$result=mysql_query("select company from dynamic where id="$id) or die(mysql_error());

if anyone help me,i will be greatful.

A(Answer):

syntax error in function argument
[PHP]// either
mysql_query("sql" . $var)
// or
mysql_query("sql $var")[/PHP]
don’t forget to sanitize your input!

regards

A(Answer):

1. Try using code tags next time
2. Try changing the code to:


$result=mysql_query("select company from dynamic where id=$id") or die(mysql_error());

I have brought the variable inside the string.

Cheers
nathj

A(Answer):

Mushfiq, to date you have named every thread you have started Dynamic Link. This explains nothing of the problem in this thread. We expect you to provide a meaningful title as it helps others who are searching the forum with the same problem.

Please take note of this as I have already warned you for not using code tags (and you have failed to do so again).

Read Posting Guidelines.

Moderator.

A(Answer):

change the code to

$result=mysql_query("select company from dynamic where `id`="$id) or die(mysql_error());

A(Answer):

@divyac this will result in the same error (for exactly the same reasons) plus the quotation marks are in the wrong place

*sigh*

for some basics on strings read this

A(Answer):

To all concerned it’s called ‘concatenation’.

LEAVE A COMMENT