Log in

View Full Version : Not able to Add Text to Database



SChaput
11-24-2008, 01:16 AM
I am using a simple weblog script found here
http://www.wsworkshop.com/php/php-mysql-weblog.html

I have modified much of it to fit my needs, i have 6 fields in my database. There fields are filled from my forum with
3 hiddenfields,
a radio button,
a drop down menu,
and a textarea. Most of the time i am able to add this information into the database without a problem, however, if my textarea is too long it is unable to add it, and errors.
All of my database fields are set to 'text' with no length value, i am just not sure why it errors if the textarea is too filled.
Example:

Misleading people into thinking he wasn't coming back tonight. This line of code throws an error.
However,

Misleading people.
Does not throw the error.
Any advice? If you need any more information id be happy to submit it.
THank you.

Schmoopy
11-24-2008, 01:21 AM
If you want people to help you with this you should really take off the "Resolved" prefix =/

thetestingsite
11-24-2008, 02:15 AM
before inserting into the database, use mysql_real_escape_string() (http://php.net/mysql_real_escape_string). Below is a modified version of the php code from the link you posted above:



<?php
if ($_POST['submit']) {
mysql_connect("server","username","password");
mysql_select_db("dbname");

$entrytitle = $_POST['entrytitle'];
$entrytext=$_POST['entrytext'];

$query ="INSERT INTO `weblog` (`entrytitle`,`entrytext`)";
$query.=" VALUES (mysql_real_escape_string($entrytitle),mysql_real_escape_string($entrytext))";

$result=mysql_query($query);

if ($result) echo "<b>Successfully Posted!</b>";
else echo "<b>ERROR: unable to post.</b>";
}
?>


Hope this helps.