a2bardeals Posted November 29, 2006 Share Posted November 29, 2006 ok so i am playing around with a simple script. a form with a post action sending to a page with the sql insert code:my form is simple:[code]<form action="do_register.php" method="POST">Name: <input type="text" name="fname" size="20">Age: <select name="age"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option></select>Favorite Color: <select name="color"><option value="red">Red</option><option value="green">Green</option><option value="blue">Blue</option><option value="orange">Orange</option><option value="purple">Purple</option><option value="pink">Pink</option></select><input type="SUBMIT" value="GO"></form>[/code]this sends the data just fine. it goes to "do_register.php"then i insert the data:[code]<?$con = mysql_connect("localhost", "user", "pass");mysql_select_db("database", $con);$sql = "INSERT INTO 'table' (`fname`, `age` , `color`)VALUES ('$_POST[fname]' , '$_POST[age]' , '$_POST[color]');";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo 'Thanks, ';echo $fname;echo '<br>Your info has been submitted!';?>[/code]it all seems fine after you post but when i call the results there is one row with the data and another blank row inserted after it. The ID row which is the index is set to auto_increment and it assignes two rows (eg. one submission = one row id:23 with the data and one row id:24 with no data.) Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/28901-extra-empty-row-or-duplicate-on-insert/ Share on other sites More sharing options...
btherl Posted November 30, 2006 Share Posted November 30, 2006 It may be your browser (or an extension, or some other add-on) making multiple requests.Another common problem is accidentally include()ing a file twice. Quote Link to comment https://forums.phpfreaks.com/topic/28901-extra-empty-row-or-duplicate-on-insert/#findComment-132531 Share on other sites More sharing options...
kid_drew Posted November 30, 2006 Share Posted November 30, 2006 Also, and not to be picky, but your insert command should reference the array members with quotes. Otherwise, it treats the string as a constant and has to figure out that it isn't, which is an extra step and will slow down the server if it has a lot of requests. To illustrate:Use this:VALUES ('{$_POST['fname']}' , '{$_POST['age']}' , '{$_POST['color']}');";Instead of:VALUES ('$_POST[fname]' , '$_POST[age]' , '$_POST[color]');";[quote author=a2bardeals link=topic=116755.msg475889#msg475889 date=1164835509]ok so i am playing around with a simple script. a form with a post action sending to a page with the sql insert code:my form is simple:[code]<form action="do_register.php" method="POST">Name: <input type="text" name="fname" size="20">Age: <select name="age"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option></select>Favorite Color: <select name="color"><option value="red">Red</option><option value="green">Green</option><option value="blue">Blue</option><option value="orange">Orange</option><option value="purple">Purple</option><option value="pink">Pink</option></select><input type="SUBMIT" value="GO"></form>[/code]this sends the data just fine. it goes to "do_register.php"then i insert the data:[code]<?$con = mysql_connect("localhost", "user", "pass");mysql_select_db("database", $con);$sql = "INSERT INTO 'table' (`fname`, `age` , `color`)VALUES ('$_POST[fname]' , '$_POST[age]' , '$_POST[color]');";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo 'Thanks, ';echo $fname;echo '<br>Your info has been submitted!';?>[/code]it all seems fine after you post but when i call the results there is one row with the data and another blank row inserted after it. The ID row which is the index is set to auto_increment and it assignes two rows (eg. one submission = one row id:23 with the data and one row id:24 with no data.) Any ideas?[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/28901-extra-empty-row-or-duplicate-on-insert/#findComment-132785 Share on other sites More sharing options...
a2bardeals Posted November 30, 2006 Author Share Posted November 30, 2006 I am using firefox 1.5.0.8 and my only other testing browser is Safari and it does not insert the extra row in Safari. So it may be a Firefox issue. But why would Firefox submit twice? It makes no sense to me and i need to fix it! Grrrrrr.If you would like to test what im working with a different browser, go to: [url=http://www.barcheese.com/newyears]http://www.barcheese.com/newyears[/url]Help! Quote Link to comment https://forums.phpfreaks.com/topic/28901-extra-empty-row-or-duplicate-on-insert/#findComment-132883 Share on other sites More sharing options...
a2bardeals Posted December 1, 2006 Author Share Posted December 1, 2006 so i am now sure it is a Firefox issue i've checked it on IE (Win/MacOS), Safari (MacOS), Firefox (Win/MacOS), & Opera. Firefox is the only one that does this! Quote Link to comment https://forums.phpfreaks.com/topic/28901-extra-empty-row-or-duplicate-on-insert/#findComment-133573 Share on other sites More sharing options...
fenway Posted December 3, 2006 Share Posted December 3, 2006 Run a non-db test to prove that the script is being called twice. Quote Link to comment https://forums.phpfreaks.com/topic/28901-extra-empty-row-or-duplicate-on-insert/#findComment-134507 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.