So I'm OK if this is all I do:
<?php
include('includes/dbconnect.php');
$title = mysql_real_escape_string($_POST['title']);
$content = mysql_real_escape_string($_POST['content']);
$query = "INSERT INTO table VALUES ('', '$title', '$content')";
$result = mysql_query($query) or die('There was an error, please <a href=\"./../contact.php\">contact</a> the administrator.');
if ($result)
echo "<br><span style='color:red'><strong>Entry Added!</strong></span>";
footer();
exit();
mysql_close();
}
?>
So forget about addslashes since mysql_real_escape_string does it for you.
How about this on the front side:
<?php
include("includes/dbconnect.php");
$query="SELECT * FROM table ORDER BY id DESC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$id = mysql_result($result,$i,'id');
$title = stripslashes(mysql_result($result,$i,'title'));
$content = nl2br(stripslashes(mysql_result($result,$i,'content')));
?>
Now I was doing this until I was told that it was a no-no:
$company = htmlspecialchars($_POST['company']);
if (!get_magic_quotes_gpc())
{
$company = addslashes($company);
}
<?php
include("includes/dbconnect.php");
$query="SELECT * FROM table ORDER BY id DESC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$id = mysql_result($result,$i,'id');
$title = stripslashes(mysql_result($result,$i,'title'));
$title = htmlspecialchars_decode($title);
$content = nl2br(stripslashes(mysql_result($result,$i,'content')));
$content = htmlspecialchars_decode($content);
?>
And this being called through the functions page:
if ( !function_exists('htmlspecialchars_decode') )
{
function htmlspecialchars_decode($text)
{
return strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
}
}
I thought that if you did not convert the <,>," and stuff to the HTML entities before putting them into the database that they would cause problems. Then you would translate them back to their original form when displaying to the public. I take it that this is indeed false?
If this is false, then why would I want to display this " instead of this " to the public? So I should just forget about the above function and
$title = htmlspecialchars_decode($title);
on the output altogether then?