0

I would like to know why I am getting a "Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING" in my code, which pulls HTML off an MySQL database, replaces < and > with the entity (&lt ;, &gt ;) and inputs it into a textarea (CKEditor). Here is that section of the code:

<textarea name="editor1">
          <?php
            //QUERY DATABASE
            $query1 = "SELECT * FROM users WHERE ID = '" . $id . "'";
            $resource1 = mysql_query($query1, $database);
            $result1 = mysql_fetch_assoc($resource1);
            $rawcode = $result['code'];\
            $code1 = str_replace("<", "&lt;", "$rawcode");
            $code = str_replace(">", "&gt;", "$code1");
            echo $code1;          
          ?>
    <!--&lt;p&gt;Create your page here.&lt;/p&gt;-->
</textarea>
1
  • \ behind $rawcode = $result['code']; Commented Sep 12, 2013 at 1:49

5 Answers 5

1

you have an extra "\" at the end of line

$rawcode = $result['code'];\

remove it

Sign up to request clarification or add additional context in comments.

1 Comment

Please upvote any answers you found helpful, and mark this answer as correct if your problem is resolved.
0

Don't try to escape the HTML yourself, use htmlspecialchars() instead.

2 Comments

what is this? The HTML is already in the DB, I just want to input it into CKEditor
Replace the 2 str_replace lines with: $code = htmlspecialchars($rawcode);
0
$rawcode = $result['code'];\

backslash is escape char in php, and escaping $ in next line. PHP parse $code1 as string that is not allowed here.

you shouldn't also use $rawcode, and $code1 in "", because it only slows slightly execution.

Comments

0

You have a syntax error in your code: Replace

 $rawcode = $result['code'];\

With

 $rawcode = $result['code'];

You can use htmlspecialchars() for your html replacement.

Replace:

$code1 = str_replace("<", "&lt;", "$rawcode");
$code = str_replace(">", "&gt;", "$code1");

With:

$code = htmlspecialchars($rawcode);

Comments

0

You have two error.

The first one is the $result variable from $rawcode = $result['code'];\. $result does not exist. You called that variable $result1.

The second one, is the \ at the end of $rawcode = $result['code'];\. You must remove it.

The end code is $rawcode = $result1['code'];

Another mistake I noticed, the last statement, echo $code1; should be echo $code; because $code contains the last change you made with str_replace.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.