Forum Moderators: open

Message Too Old, No Replies

Insert creates 2 records instead of 1 JUST with IE7

This is real crazy!

         

smagdy

8:57 am on Jun 18, 2007 (gmt 0)

10+ Year Member



Hello!

I am using PHP 4.7 and i am doing a normal insert, it works fine in FF and Safari, but IE7 always insert 2 records at once!

How could this happen?

here is the part of code where it inserts...

if($_SESSION['edit_ad']!= "")
$sql = "UPDATE `ads` SET `name` = '".$_SESSION["name"]."' ..... where id = '".$_SESSION['edit_ad']."' LIMIT 1";
else
$sql = "INSERT INTO `ads` ( `name` , ......)
VALUES ( '".$_SESSION["name"]."' , ....)";

if(mysql_query($sql))
{
session_write_close();
header("Location: confirm");
exit;
}

Please try to tip me with any solution to this crazy thing!

Thanks in advance.

joelgreen

1:43 pm on Jun 18, 2007 (gmt 0)

10+ Year Member



I think you should look for problem on client side (html/javascript) since your code is working ok with other than IE7 browsers. Looks like IE forces double click for some reason. Try disabling post button using Javascript as soon as it is clicked.

smagdy

10:29 am on Jun 19, 2007 (gmt 0)

10+ Year Member



Well thanks for the advice but i am using an image button, could this be a reason or buy in IE7?

henry0

11:35 am on Jun 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if($_SESSION['edit_ad']!= "")
$sql = "UPDATE `ads` SET `name` = '".$_SESSION["name"]."' ..... where id = '".$_SESSION['edit_ad']."' LIMIT 1";
else
$sql = "INSERT INTO `ads` ( `name` , ......)
VALUES ( '".$_SESSION["name"]."' , ....)";

It looks like regardless of the condition your script is executed twice (once for each cond)
try
elseif($_SESSION['edit_ad']== "")
{
$sql = "INSERT INTO `ads` ( `name` , ......)
VALUES ( '".$_SESSION["name"]."' , ....)";
}

smagdy

11:46 am on Jun 19, 2007 (gmt 0)

10+ Year Member



i tried it, but it still creates 2 records!

it even looks like this now:

if($_SESSION['edit_ad']!= "")
{
$sql = "UPDATE(....)";
}
else
if($_SESSION['edit_ad'] == "")
{
$sql = "INSERT(....)";
}

if(mysql_query($sql))
{
session_write_close();
header("Location: confirm");
exit;
}

henry0

4:55 pm on Jun 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a "procedural" idea
reverse the process:

Firstly start by checking if it exists

if not perform an insert and exit()
if yes then it is an update

aspdaddy

7:59 pm on Jun 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use some javascript to disbale the submit butons/images after they are clicked, stops the double-click problem.

Likely that your form post and the image-button handler are both posting the data so the above may not work

smagdy

8:38 pm on Jun 21, 2007 (gmt 0)

10+ Year Member



"the above may not work"

You mean your solution or the solution above it?

am sorry am out of town so i cant try both solutions now, so i was just wondering which solution did u mean?

Thanks

smagdy

10:01 pm on Jun 24, 2007 (gmt 0)

10+ Year Member



Thanks for the solutions..

I got it working finally..

I was submitting the form when the image was clicked, thought the image acts as submit by default (which i didn't know)

But it was strange that it worked like that just in IE