0

I'm trying to create a discussion forum using PHP. I have declared a post table for different posts with attributes(columns) such as id and content.

Content is of type "LONGTEXT", collation "latin1_swedish_ci"

This was on the database part.

Now the PHP coding is as follows

if(!$_SESSION['signed_in'])
{
    echo 'You must be signed in to post a reply.';
}
else
{
    //a real user posted a real reply
    $sql = "INSERT INTO 
                posts(post_content,
                      post_date,
                      post_topic,
                      post_by) 
            VALUES ('" . $_POST['reply-content'] . "',
                    NOW(),
                    " . Mysql_real_escape_string($_GET['id']) . ",
                    " . $_SESSION['user_id'] . ")";

    $result = mysql_query($sql);

    if(!$result)
    {
        echo 'Your reply has not been saved, please try again later.';
    }
    else
    {
        echo 'Your reply has been saved, check out <a href="topic.php?id=' . Htmlentities($_GET['id']) . '">the topic</a>.';
    }
}   

Now comes the problem part. For most of the posts, I'm getting this error:

Your reply has not been saved, please try again later.

When my post content is large (length wise), this message certainly appears. But this error may appear at random too.

The query is not executing somehow how I guess. I'm using "longtext" so length shouldn't be the issue.

Can anybody find the real error?

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
  • Why are you not escaping your reply-content? – Musa Mar 10 '13 at 20:16
  • 1
    You're using a deprecated library and your code is vulnerable at sql-injection – Sam Mar 10 '13 at 20:16
  • 1
    possible duplicate of [Why shouldn't I use mysql\_\* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – mario Mar 10 '13 at 20:32
  • Check whether mysql_query is executing or not by $result = mysql_query($sql) or die (mysql_error()); So that you can see what happen, when it is not executing. – Tahmina Khatoon Mar 22 '13 at 00:28

0 Answers0