Troubles sending textarea data to a database

I'm trying to create a php form that sends textarea data to database. The database table uploads has 3 data items that are needed:

  • user_id
  • category
  • content

HTML:

<form id="myform" action="php/savetext.php" method="POST" enctype="multipart/form-data">

  <p><strong>Add your story here.</strong></p>

        <input type="hidden" name="fbid" id="fbid">
        <input type="hidden" name="category" id="category">

        <textarea cols="50" rows="10" name="usertext" id="storyArea"></textarea>
        <input type="submit" name="submit" value="Saada" />

        <script type="text/javascript">

            $( "#fbid" ).val( "sdf88d99sd" );
            $( "#category" ).val( "texts" );    

        </script>                       
</form>

savetext.php:

include_once('config.php');

if (isset($_POST['user_id']) && isset($_POST['category']) && isset($_POST['usertext'])) {

    $user_id = mysql_real_escape_string($_POST['fbid']);
    $category = mysql_real_escape_string($_POST['category']);
    $content = mysql_real_escape_string($_POST['usertext']);
    addUser($user_id, $category, $content);
}

else {
    echo 'Upload failed! Try again.';
}

function addUser($user_id, $category, $content) {
    $query = "SELECT id FROM uploads WHERE user_id = '$fbid' LIMIT 1";
    $result = mysql_query($query);
    $rows = mysql_num_rows($result);
    if ($rows > 0) {
        $query = "UPDATE uploads SET user_id = '$user_id', category = '$category' WHERE content = '$content'";
    }
    else {
        $query = "INSERT INTO uploads (user_id, category, content) VALUES ('$user_id', '$category', '$content')";
    }
    mysql_query($query);
    echo 'Upload was succesful. Thank you!';

}

But this doesn't work. Any ideas on how to correct this?

Answers


please review this code ,there is no field with name user_in in <form></form>

if (isset($_POST['fbid']) && isset($_POST['category']) && isset($_POST['usertext'])) {

    $user_id = mysql_real_escape_string($_POST['fbid']);
    $category = mysql_real_escape_string($_POST['category']);
    $content = mysql_real_escape_string($_POST['usertext']);
    addUser($user_id, $category, $content);
}

Need Your Help

Retrieve data from bad formatted database

php mysql

I have to make a report from very old mysql database (about year 2003). So the style is bad.

Play Logback only show class 'play.Logger$ALogger'

logging playframework playframework-2.0 logback

I use the next Logback pattern into Play! Framework application: