Query executes twice with IE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Query executes twice with IE

Post by someberry »

I have tried the code in quite a few browsers, and this error only effects IE. For some reason, the query is executed twice. I have pinpointed it to when I press the enter key on one of the inputs instead of clicking the submit button directly.

I have also tried adding a simple echo statement just before the query, it only ever prints it out once.

This is the code I am using:

The form

Code: Select all

<p>Subject<br />
<input type="text" name="subject" /><br />
Message<br />
<textarea name="message" rows="10" cols="45"></textarea><br />
<input type="submit" name="submit" value="Submit" />
The class caller

Code: Select all

$mail = new Mail();
$mail -> send_msg();
The class

Code: Select all

class Mail
{
	var $msg;	// Store any error/success messages
	
	function __construct() { /* Dont do anything */ }
	
	function send_msg()
	{
		// Send the message
		mysql_query("INSERT INTO `mail`(`subject`,									`message`)
								 VALUES('" . htmlentities($_POST['subject']) . "',	'" . htmlentities($_POST['message']) . "')
					") or die(mysql_error());
									    
		$this -> msg = '<p><span class="notice">Success</span>: mail sent successfully.</p>';
	}
}
?>
As you can see, it is pretty basic stuff. However, IE seems to replicate the exact query, which is very fustrating. I am using ApacheFriends XAMPP Lite version 1.5.2 as my localhost (which is PHP5), but the problem remains even on my server which is running PHP4.

Does anyone have any ideas why this might be happening?
Thanks,
someberry
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

Post by hairyjim »

What version of IE are you using? Are you perhaps using IE 7?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

What does the whole script look like? Post it here
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Do you think IE is posting data twice?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Yargh
Last edited by Benjamin on Tue Jul 25, 2006 5:17 am, edited 2 times in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Hehe, firefox
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Post by someberry »

Oh dear, this is rather embarrassing. :oops:

Thanks to hairyjim who got my brain into gear with what version of IE I was using. I was using IE via Firefox's IETab extention. Seems it maybe posts it using Firefox and IE. Oops.

Just tried it on the real IE and it works.

Thanks everyone,
someberry
Post Reply