I want to store the $newreg buffer data to mysql database. I tried with text and BLOB in mysql, but it returns error 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 '179' height='100' />',2)' at line 1
Or is there any other way to do this?
ob_start();
echo("
<div class='templadf_section_2'>");
echo("<img src=$tprofpic1 alt=$description />");
echo("<h4>For sale at $district</h4>");
echo("<p>$description</p>");
echo("<div class='price'>PRICE:<span> $expectedprice INR</span></div>");
echo("<div class='readmore'><a href=$tempath>Read more</a></div>");
echo("</div>");
$newreg=ob_get_clean();
Without seeing your mysql query I couldn't say for sure, but if I had to guess I would say you are not escaping the apostrophes in your query. Make sure you are running the data through mysql_real_escape_string() prior to running your queries.
As Dagon said, you should assign the string to $newreg instead of using output buffering. If it is spread out among the code user $newreg .= "string" to append more to the string. Using ob works, but it adds additional overhead and depending on your code could allow for unintended text to be added to the string
Other than what @CJ Wurtz's answer, I only see this solution: it seems that, You are either not using quotes for numeric value or Your input data isn't cleaned/escaped before use.
Try this
$newreg = mysql_real_escape_string(stripslashes(ob_get_clean()));
This will escape the single quotes in your string/entry.