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
https://forums.phpfreaks.com/topic/250157-adding-2-results-with-1-query/
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.