I added code to turn bbcode into html and now it won't add to the database.
what is wrong
<?
include ('../inc/db.php');
// Define post fields into simple variables
$teacher=$_POST['teacher'];
$topic=$_POST['topic'];
$date=$_POST['date'];
$notes = $_POST['notes'];
/* Lets strip some slashes in case the user entered
any escaped characters. */
$teacher = addslashes($teacher);
$topic = addslashes($topic);
$date = addslashes($date);
$notes = addslashes($notes);
/* Do some error checking on the form posted fields */
if((!$date) || (!$notes)){
echo 'You did not submit the following required notesrmation! <br />';
if(!$date){
echo "The date is a required field. Please enter it below.<br />";
}
if(!$notes){
echo "Notes is a required field. Please enter it below.<br />";
}
include 'postnotes.php'; // Show the form again!
/* End the error checking and if everything is ok, we'll move on to
creating the user account */
exit(); // if the error checking has failed, we'll exit the script!
}
/* Time to add the line breaks to the notes */
nl2br($notes);
/* well lets make the BBCode into html. Its easier for the user to do [b] insted of <b> or [url]blah[/url] insted of <a href="balh">blah</a> */
function bb2html($notes)
{
$bbcode = array("<", ">",
"[list]", "[*]", "[/list]",
"[img]", "[/img]",
"[b]", "[/b]",
"[u]", "[/u]",
"[i]", "[/i]",
'[color="', "[/color]",
"[size=\"", "[/size]",
'[url="', "[/url]",
"[mail=\"", "[/mail]",
"[code]", "
",
"
",
'"]');
$htmlcode = array("<", ">",
"<ul>", "<li>", "</ul>",
"<img src=\"", "\">",
"<b>", "</b>",
"<u>", "</u>",
"<i>", "</i>",
"<span style=\"color:", "</span>",
"<span style=\"font-size:", "</span>",
'<a href="', "</a>",
"<a href=\"mailto:", "</a>",
"<code>", "</code>",
"<table width=100% bgcolor=lightgray><tr><td bgcolor=white>", "</td></tr></table>", '">');
$newnotes = str_replace($bbcode, $htmlcode, $newnotes);
$newnotes = nl2br($newnotes); //second pass
return $newnotes;
}
/* Everything has passed both error checks that we have done.
It's time to add the notes! */
// Enter notes into the Database.
$newnotes = htmlspecialchars($newnotes);
$sql = mysql_query("INSERT INTO notes (teacher, topic, date, notes)
VALUES('$teacher', '$topic', '$date', '$newnotes')") or die (mysql_error());
if(!$sql){
echo 'There has been an error adding your notes. Please contact the webmaster.';
} else {
echo 'Your class notes were added. Thanks and continue using this service. Back to <a href=\"sample.php\">index</a>';
}
?>
<? include("http://jaygreentree.xoopiter.com/ads.php"); ?> [/code]