Jump to content


Photo

inserts multiple rows into MySql


  • Please log in to reply
4 replies to this topic

#1 mrblack

mrblack
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 28 February 2006 - 04:23 PM

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.

#2 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 28 February 2006 - 04:27 PM

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.

#3 loki_racer

loki_racer
  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 28 February 2006 - 04:40 PM

An easy way to avoid this is force a redirect after the form information has been submitted to the database via:

header("Location: nextpage.php");

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

"It's time to roll the dice."

#4 mrblack

mrblack
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 28 February 2006 - 04:49 PM

[!--quoteo(post=350257:date=Feb 28 2006, 11:27 AM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Feb 28 2006, 11:27 AM) View Post[/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

#5 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 28 February 2006 - 05:09 PM

Is it possible someone else is on your site? Maybe you should log IPs that use the form and see.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users