ecabrera Posted November 20, 2011 Share Posted November 20, 2011 Parse error: syntax error, unexpected '"' in /home/wesbite/public_html/admin.php on line 14 <?php require("scripts/connect.php"); $sqlCommand = ("SELECT * FROM content"); $query = mysql_query($sqlCommand); while ($row = mysql_fetch_array($query)) { // Gather all $row values into local variables for easier usage in output $intro = stripslashes(str_replace("\","",$row['intro'])); $latestnews = stripslashes(str_replace("\","",$row['latestnews'])); $maincontent= stripslashes(str_replace("\","",$row['maincontent'])); $mainvideos = stripslashes(str_replace("\","",$row['mainvideos'])); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/251461-syntax-error/ Share on other sites More sharing options...
RussellReal Posted November 20, 2011 Share Posted November 20, 2011 change "\" to "\\" Quote Link to comment https://forums.phpfreaks.com/topic/251461-syntax-error/#findComment-1289654 Share on other sites More sharing options...
ecabrera Posted November 20, 2011 Author Share Posted November 20, 2011 but i want to change \ to make nothing Quote Link to comment https://forums.phpfreaks.com/topic/251461-syntax-error/#findComment-1289660 Share on other sites More sharing options...
xZachtmx Posted November 20, 2011 Share Posted November 20, 2011 A backslash is an escape character in mysql, so like the above post said, you need to use two of them to say that you dont want to use it as an escape character. If you use only one, it tells your program that the following double quote should be included as part of your string. Quote Link to comment https://forums.phpfreaks.com/topic/251461-syntax-error/#findComment-1289664 Share on other sites More sharing options...
ecabrera Posted November 20, 2011 Author Share Posted November 20, 2011 ok Quote Link to comment https://forums.phpfreaks.com/topic/251461-syntax-error/#findComment-1289670 Share on other sites More sharing options...
ecabrera Posted November 20, 2011 Author Share Posted November 20, 2011 i get this Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/website/public_html/admin.php on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/website/public_html/admin.php on line 14 Parse error: syntax error, unexpected '"' in /home/website/public_html/admin.php on line 14 <?php require("scripts/connect.php"); $sqlCommand = ("SELECT * FROM content"); $query = mysql_query($sqlCommand); while ($row = mysql_fetch_array($query)) { // Gather all $row values into local variables for easier usage in output $intro = stripslashes(str_replace("\","\\",$row['intro'])); $latestnews = stripslashes(str_replace("\","\\",$row['latestnews'])); $maincontent= stripslashes(str_replace("\","\\",$row['maincontent'])); $mainvideos = stripslashes(str_replace("\","\\",$row['mainvideos'])); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/251461-syntax-error/#findComment-1289672 Share on other sites More sharing options...
mikesta707 Posted November 20, 2011 Share Posted November 20, 2011 Ok, first I suggest you do a little more research into PHP, as you don't seem to even know about basic syntax rules. What exactly are you trying to do here, because the outcome from the first snippet of code (if it was written correctly) is completely different from the outcome of the second. The first is removing slashes, while the second is.. trying.. to replace all backslashes in those strings with 2 back slashes. If you simply want to remove the slashes from the string use stripslashes $intro = stripslashes($row['intro']); If you really really want to do whatever it is your trying to do in the second example, you need to escape backslashes in a string or else PHP thinks your trying to escape the quote. In order to do that, you use.. well the escape character which is backslash. This results in a double backslash "\\". Google PHP escape characters (or just escape characters, since its a language independent construct) to read about how these work. while ($row = mysql_fetch_array($query)) { // Gather all $row values into local variables for easier usage in output $intro = stripslashes(str_replace("\\","\\\\",$row['intro'])); $latestnews = stripslashes(str_replace("\\","\\\\",$row['latestnews'])); $maincontent= stripslashes(str_replace("\\","\\\\",$row['maincontent'])); $mainvideos = stripslashes(str_replace("\\","\\\\",$row['mainvideos'])); } again, I don't see why you would want to do the above though. it just turns 1 backslash into 2. BTW, you should be using a more advanced text editor than notepad, as any IDE, like dreamweaver or notepad++ would make syntax errors like what you have obvious. Even the forums code tags make them pretty obvious. You can see the string (the red) continuing into the comma after the first double quote. Quote Link to comment https://forums.phpfreaks.com/topic/251461-syntax-error/#findComment-1289685 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.