Results 1 to 3 of 3

Thread: Not able to Add Text to Database

  1. #1
    Join Date
    Feb 2008
    Posts
    90
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default Not able to Add Text to Database

    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.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    If you want people to help you with this you should really take off the "Resolved" prefix =/

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    before inserting into the database, use mysql_real_escape_string(). Below is a modified version of the php code from the link you posted above:

    Code:
     <?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.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •