Jump to content

Adding 2 results with 1 query?


RaythMistwalker

Recommended Posts

If ($_GET['CODE'] == '1') {
    $ThreadID = mysql_escape_string($_GET['threadid']);
    $ForumID = mysql_result(mysql_query("SELECT forum_id FROM ".FORUM_THREADS." WHERE thread_id='{$ThreadID}'", $db), 0, 'forum_id');
    $PostText = mysql_escape_string($_POST['replytext']);
    $IP = $_SERVER['REMOTE_ADDR'];
    $PostQuery = "INSERT INTO ".FORUM_POSTS." (`user_id`, `thread_id`, `post_text`, `forum_id`, `ip_address`, `timestamp`) VALUES ('{$memid}', '{$ThreadID}', '{$PostText}', '{$ForumID}', '{$IP}' , CURRENT_TIMESTAMP)";
    $PostRes = mysql_query($PostQuery, $db);

 

For some reason whenever this query goes through, it also adds a blank result using all the same information but without any $PostTest so essentially it does query:

 

INSERT INTO ".FORUM_POSTS." (`user_id`, `thread_id`, `post_text`, `forum_id`, `ip_address`, `timestamp`) VALUES ('{$memid}', '{$ThreadID}', '', '{$ForumID}', '{$IP}' , CURRENT_TIMESTAMP)

 

This is the only query that does this part of the code and I can't see why it is adding 2 queries.

 

FORUM_POSTS = constant containing table name.

Link to comment
Share on other sites

The browser is probably requesting the page twice, once with $_POST data and once without. There are several reasons why different browsers do this, some within your control (url rewriting, redirecting to the same page,...) and some outside your control (which browser is being used and which add-on's it has.)

 

Are you not validating that a form was submitted and that $_POST['replytext'] is not empty?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.