Jump to content

Archived

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

mrblack

inserts multiple rows into MySql

Recommended Posts

Hi,

I am facing a vierd problem.

I do a insert with the data from a form. It gets updated fine into the database. Then i go to some other page and come back to the first page and i find that there are multiple entries of the previous data and the number is not fixed, it chages each time.

I have tried changing the auto increment and manually updating the serial number, still i see the same issue.

Any suggestions would be appretiated.

Thanks in advace.

Ducane.

Share this post


Link to post
Share on other sites
Are you using your back button? Some browsers repost form data without warning you.

Without seeing some code I'm afraid I can't be any more help than that.

Share this post


Link to post
Share on other sites
An easy way to avoid this is force a redirect after the form information has been submitted to the database via:

[code]header("Location: nextpage.php");[/code]

This will make it so that when someone uses the back button to return to the form, it will be the blank version.

Share this post


Link to post
Share on other sites
[!--quoteo(post=350257:date=Feb 28 2006, 11:27 AM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Feb 28 2006, 11:27 AM) [snapback]350257[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Are you using your back button? Some browsers repost form data without warning you.

Without seeing some code I'm afraid I can't be any more help than that.
[/quote]

$db = mysql_connect("localhost", "root", "root");
mysql_select_db("pts_extend", $db);

if (isset( $_REQUEST[add])) {
if(!($_REQUEST[add] == '')) {

$addValue = $_REQUEST[add];

$infoTypeResult = mysql_query("select itemtype from info_type", $db);

$maxValue = 0;

while ($infoRow = mysql_fetch_array($infoTypeResult)) {
if($infoRow[itemtype] > $maxValue) {

$maxValue = $infoRow[itemtype];

}
}

$maxValue++;

mysql_query("insert into info_type (itemtype,description) values ('$maxValue','$addValue')", $db);

mysql_query("commit");

}
}

if 'add' is set in request parameters, it will insert a row.
i know that if i do a refersh, that should add one more row. But i actually navigate to another page and by buttons and navigate back.
the number of rows may or may not be added and if added they are in random numbers - so that's really unexplainable.

I am not sure which one of apache, mySql or Php is doing that!

header("Location: nextpage.php");

good one.

my primary concern is inserting random addition.

This is how that looks, initially it did not show multiple entries!

Id Description
1 Deployment
2 BRD Ready
3 Tech Design
4 HLE
5 ewr ewr
6 wer t
7 ewr ewr
8 ewr ewr
9 ewr ewr
10 ewr ewr
11 ewr ewr
12 ewr ewr
13 ewr ewr
14 ewr ewr
15 ewr ewr

Share this post


Link to post
Share on other sites

×

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.