Jump to content
xisto Community
Sign in to follow this  
beeseven

Writing To Database Problem With Mysql - Not Writing Forum Post

Recommended Posts

I'm making a forum and I've had several problems tonight which I've come here to ask then found the answer to myself, but this one is stumping me. Whenever it goes to write the post to the database, it saves the poster, and the time, but the part where the message would go is empty. Here's the code, with comments about what it's supposed to do (what I wanted it to do and thought it did):

$imsg = stripslashes($_POST['msg']); //Get message	if(strlen($imsg) > 5 && strlen($imsg) < 10240) //Check length	{  $imsg = htmlspecialchars($imsg); //Change stuff to entities  $imsg = str_replace("&","&",$imsg); //Change ampersands back  $allowedentities = array('<b>','</b>','<i>','</i>','<u>','</u>','<B>','</B>','<I>','</I>','<U>','</U>','<br>','<BR>','<Br>','<bR>'); //Tell which entities to change into tags  $allowedtags = array('<b>','</b>','<i>','</i>','<u>','</u>','<B>','</B>','<I>','</I>','<U>','</U>','<br>','<BR>','<Br>','<bR>'); //Tell which tags to turn them into  $imsg = str_replace($allowedentities,$allowedtags,$imsg); //Replace  $msg = nl2br($imsg); //Add line breaks  echo "<table class=\"posts\"><tr><td class=\"msg\">$msg</td></tr></table><br><form method=\"post\" action=\"temppost.php\" name=\"f2\"><input type=\"submit\" name=\"post\"value=\"Post Message\"></form>"; //Display preview of post and post button	}
That's how it takes the message and processes it. The rest is as follows:
$postedby = $username; //Get user posting	$postedon = date("F jS, Y \a\\t g:i:sa"); //Get date/time	mysql_query("INSERT INTO `tempposts` (`postedby`,`postedon`,`msg`) VALUES ('$postedby','$postedon','$msg')"); //Send it to database
I'm not sure if it's something about the $msg variable being available in the different parts or the mySQL table. I'm kind of new to it. The data type for the message was originally a BLOB, if that matters. I tried changing it to TEXT and it still didn't work.

Share this post


Link to post
Share on other sites

i tested your srcipt by using my own database and substituted a fixed value for $imsg and $postedby. it worked for me so i am really wondering now what happened.

Share this post


Link to post
Share on other sites
:) I figured it out! I feel pround now (and a bit nerdy). The problem had to do with refreshing variables or something similar. I just had it store the message as a session variable, and then it was available to the second part to write to the database. Thanks mobious for figuring out it wasn't a mySQL problem.

Share this post


Link to post
Share on other sites

:) I figured it out! I feel pround now (and a bit nerdy). The problem had to do with refreshing variables or something similar. I just had it store the message as a session variable, and then it was available to the second part to write to the database. Thanks mobious for figuring out it wasn't a mySQL problem.

67926[/snapback]


no prob! :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.