Question:

PHP database question?

by  |  earlier

0 LIKES UnLike

Hello,

For my comment feature on my site, I save html code to a database. I want to set the background color of a table within that code, but when I save

<table bgcolor="55555">

or something similar to the database via php, the computer gets confused and thinkgs that bgcolor is a php variable, and gives the unexpected T_STRING error. How can I fix this?

 Tags:

   Report

2 ANSWERS


  1. When you are inserting the comment into your database, make sure you do something like:

    $_POST[&#039;comment&#039;] = addslashes($comment);

    or

    $_POST[&#039;comment&#039;] = mysql_real_escape_string($comment);

    Then remove slashes before printing / echoing it, like this:

    $sql = &quot;SELECT comment FROM comments&quot;;

    while ($row = mysql_fetch_array($sql)) {

    $comment = stripslashes($row[&#039;comment&#039;]);

    print $comment;

    }


  2. Paste the full error question from the PHP execution.

    I think u hv placed unwant ;, &quot;, &#039;, $ etc.,

    Basically it syntax error... Check out properly...
You're reading: PHP database question?

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.