You are here: Re: Form submits the same record twice? « PHP SQL « IT news, forums, messages
Re: Form submits the same record twice?

Posted by Paul Lautman on 01/21/07 16:12

egibberate wrote:
> "egibberate" <colingray45@btinternet.com> wrote in message
> news:As-dnRDIM4IdGi7YnZ2dnUVZ8rKdnZ2d@bt.com...
>> "egibberate" <colingray45@btinternet.com> wrote in message
>> news:fYSdnbWy94w86C7YRVnytAA@bt.com...
>>> Hi,
>>>
>>> complete novice I'm afraid. When I input data into the form
>>>
>>> and click the submit button, the data is sent to the database
>>> twice ?
>>>
>>> ie. two identical records are logged into the table. Can anyone
>>> spot the
>>>
>>> flaw in the code below? Thanks in anticipation.
>>>
>>> <?
>>>
>>> if ($_POST) {
>>>
>>> $msg = "";
>>>
>>> foreach($_POST as $k => $v) {
>>>
>>> $v = trim($v) ;
>>>
>>> $$k = $v ;
>>>
>>> if ($v=="") {
>>>
>>> $msg = "Please fill in both fields";
>>>
>>> }
>>>
>>> }
>>>
>>> if ($msg=="") {
>>>
>>> $insert = "INSERT INTO tblshop_name
>>>
>>> (strshop_name, intshopcentre)
>>>
>>> VALUES ('$sn','$sc')";
>>>
>>> $link = mysqli_connect('localhost','root','blablabla','blablabla');
>>>
>>> if (!mysqli_query($link, $insert)) {
>>>
>>> $msg = "Error inserting data";
>>>
>>> } else {
>>>
>>> $msg = "Record successfully added";
>>>
>>> $sn = $sc = "";
>>>
>>> }
>>>
>>> mysqli_close($link);
>>>
>>> }
>>>
>>> echo "<div class=\"error\">$msg</div>";
>>>
>>> } else {
>>>
>>> $sn = $sc = "";
>>>
>>> }
>>>
>>>>
>>>
>>> <FORM METHOD="post" ACTION="<? echo
>>>
>>> $_SERVER['PHP_SELF'] ?>">
>>>
>>> <TABLE BORDER="1" CELLPADDING="5">
>>>
>>> <TR>
>>>
>>> <TH>Shop Name</TH>
>>>
>>> <TH>Retail Park</TH>
>>>
>>> </TR>
>>>
>>> <TR>
>>>
>>> <TD><INPUT TYPE="text" NAME="sn" VALUE"<?
>>>
>>> echo $sn ?>" /></TD>
>>>
>>> <TD><INPUT TYPE="text" NAME="sc" VALUE="<?
>>>
>>> echo $sc ?>" /></TD>
>>>
>>> </TR>
>>>
>>> </TABLE>
>>>
>>> <BR/>
>>>
>>> <INPUT TYPE="submit" VALUE="Add to database" />
>>>
>>> <INPUT TYPE="reset" VALUE="Cancel" />
>>>
>>> </FORM>
>>>
>>>
>> Hi again,
>> I copied the following two lines
>> from the apache server access log that
>> shows the data being sent two times,
>> 39 seconds apart. Curious!
>> 127.0.0.1 - - [21/Jan/2007:14:54:20 +0000] "POST /blablablabla.php
>> HTTP/1.1" 200 2140
>> 127.0.0.1 - - [21/Jan/2007:14:54:59 +0000] "POST /blablablabla.php
>> HTTP/1.1" 200 2140
>
> Hi yet again,
> every time I click the refresh button on my
> browser another identical record to the last, is entered into the
> table even tho the form has nothing typed in the text boxes.

Most browsers when you hit refresh on a posted page popup a warning that the
data will be re-submitted. I'm surprised that your one doesn't.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация