May 16, 2013
Parse error: syntax error, unexpected T_STRING in /// on line 3
User2373405’s Question:
i have writeen a php code to replace SQL row values. but some thing went wrong when i ran this.
ERROR : Parse error: syntax error, unexpected T_STRING in …… on line 3
i think i should not use these " "
right ? any other corrections…
when i ran this without " "
got this error
Error updating comment table: 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 ‘1’ at line 1
<?php
include_once("db.php");
$sql1 = "update table1 set marks = replace(c2,"NK",'NOKIA')";
$sql2 = "update table1 set marks = replace(c2,"SM",'SAMSUNG')";
$sql3 = "update table1 set marks = replace(c2,"A",'APPLE')";
$sql4 = "update table1 set marks = replace(c2,"CH",'CHINAPECE')";
$sql5 = "update table1 set marks = replace(c2,"WO",'WORLDCLASS')";
if (mysql_query($sql1 && $sql2 && $sql3 && $sql4 && $sql5))
{
echo "Replaced.";
}
else
{
echo "Error in replacing: " . mysql_error();
}
?>
Thank you!
Your problem is due to unescaped quotes. Use Single Quotes to define the values in a query string. It is less confusing that way.
Also there is a problem with the statements. Since you are combining statements they have to terminated using delimeter ;
$sql1 = "update table1 set marks = replace(c2,'NK','NOKIA');";
$sql2 = "update table1 set marks = replace(c2,'SM','SAMSUNG');";
$sql3 = "update table1 set marks = replace(c2,'A','APPLE');";
$sql4 = "update table1 set marks = replace(c2,'CH','CHINAPECE');";
$sql5 = "update table1 set marks = replace(c2,'WO','WORLDCLASS');";
And query like this:
mysql_query($sql1);
mysql_query($sql2);
mysql_query($sql3);
mysql_query($sql4);
mysql_query($sql5);