Jump to content

syntax error


ecabrera

Recommended Posts

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']));
}
?>

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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']));
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.