Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
My form resubmits on refresh
Old 01-04-2006, 07:33 AM My form resubmits on refresh
hiptobesquare's Avatar
Extreme Talker

Posts: 186
Location: London UK
Trades: 0
Hello. Im using PHPSELF to submit a form and take the user to a thankyou page when theyve filled in all the required info. The form works fine except that on clicking refresh from the thankyou page resubmits all the form info and i get a repeated line on my database table. Im sure there is a very simple way around this i just dont know what it is.. anybody?

Here is the Code:

PHP Code:
<html>
<head>
</head>
<body>
          <?php 
if(isset($submit))
{  echo
"<style type='text/css'>#normalBold {color:red;}</style>";}  
     
$name $_POST["name"];
     
$address1 $_POST["address1"];
     
$address2 $_POST["address2"];
     
$address3 $_POST["address3"];
     
$postcode $_POST["postcode"];
     
$email $_POST["email"];
     
$bob='0';
     
$error_name=''
     
$error_address=''
     
$error_postcode=''
     
$error_email=''
if(
trim($name)    =='' || strlen(trim($name))    <|| strlen(trim($name))>30){  $error_name.="Name:";         $bob='1'; } 
if(
trim($address1)=='' || strlen(trim($address1))<4)                          {  $error_address.="Address:";   $bob='1'; } 
if(
trim($postcode)=='' || strlen(trim($postcode))<4)                          {  $error_postcode.="Postcode:"$bob='1'; } 
if(
trim($email)   =='')                                                       {  $error_email.="Email:";       $bob='1'; }
else{  if(!
ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]"$email)) {$error_invalidemail.="Please enter a valid email address"$error_email.="Email:"$bob='1';} 
  else if( 
ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]"$email)) {$error_email.="";} }

      
 if (
$bob== "1"){?>
 
 
          <form method="post" action="<?php echo $PHP_SELF;?>"> 
            <table cellspacing='2' cellpadding="5" border="0" bordercolor='#8EBF85' align="center">
              <tr>
                <td colspan="2">
                <span id="normal">Enter your details below and click up to 5 boxes corresponding to the colourchip samples you would like and we 
                                  will send them to you immediately. 
                </span>
                </td>
              </tr>
              <tr  valign="top">
                <td width="" >
                  <table border="0" align="left">
                    <tr>
                      <td align='right'><span id="normalBold"><?php echo"$error_name";?>      </span></td>
                      <td><input type="text" name="name" size="25" maxlength="25" class='inputBox' value="<? echo $name?>"></td>
                    </tr>
                    <tr valign='top'>
                      <td align='right'><span id="normalBold"><?php echo"$error_address";?>   </span></td>
                      <td><input type="text" name="address1" size="25" maxlength="25" class='inputBox' value="<? echo $address1?>"><br>
                          <input type="text" name="address2" size="25" maxlength="25" class='inputBox' value="<? echo $address2?>"><br>
                          <input type="text" name="address3" size="25" maxlength="25" class='inputBox' value="<? echo $address3?>">
                      </td>
                    </tr> 
                    <tr>
                      <td align='right'><span id="normalBold"><?php echo"$error_postcode";?>  </span></td>
                      <td><input type="text" name="postcode" size="25" maxlength="25" class="inputBox" value="<? echo $postcode?>"></td>
                    </tr>
                    <tr>
                      <td align='right'><span id="normalBold"><?php echo"$error_email";?>     </span></td>
                      <td><input type="text" name="email"    size="25" maxlength="50" class='inputBox' value="<? echo $email?>"><br></td>
                    </tr>
                    <tr>
                      <td colspan="2">  <span id="normalBold"><?php echo "$error_invalidemail";?></span></td>
                    </tr>
                  </table>
                </td>
                <td valign="bottom">
                  <table border="0" bordercolor="#696969">
                    <tr>
                      <td width="52"><img src="images/sample0.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td  width="52"><img src="images/sample1.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td><img src="images/sample2.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td><img src="images/sample3.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td><img src="images/sample4.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td><img src="images/sample5.gif"></td><td width="1" ></td>
                    </tr> 
                    <tr height="1">
                      <td bgcolor="#696969" colspan="12"></td>
                    </tr>
                    <tr>
                      <td><input type="checkbox" name="colourchip[]" value="Silver Mirror"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="Dove White"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="Flame Red"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="Orchard Green"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="Ocean Blue"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="Metallic Blue"></td><td width="1" ></td>
                    </tr>
                    <tr height="1">
                      <td bgcolor="#696969" colspan="12"></td>
                    </tr>
                    <tr>
                      <td><img src="images/sample6.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td><img src="images/sample7.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td><img src="images/sample8.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td><img src="images/sample9.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td><img src="images/sample10.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td><img src="images/sample11.gif"></td><td width="1" ></td>
                    </tr>
                    <tr height="1">
                      <td bgcolor="#696969" colspan="12"></td>
                    </tr>
                    <tr>
                      <td><input type="checkbox" name="colourchip[]" value="Titanium"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="Sky Blue"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="Jet Black"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="Bordeaux"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="Fuschia"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="Lilac"></td><td width="1"></td>
                    </tr>
                    <tr height="1">
                      <td bgcolor="#696969" colspan="12"></td>
                    </tr>
                    <tr>
                      <td><img src="images/sample12.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td><img src="images/sample13.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td><img src="images/sample14.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td><img src="images/sample15.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td><img src="images/sample16.gif"></td><td width="1" bgcolor="#696969"></td>
                      <td><img src="images/sample17.gif"></td><td width="1" ></td>
                    </tr>
                    <tr height="1">
                      <td bgcolor="#696969" colspan="12"></td>
                    </tr> 
                    <tr>
                      <td><input type="checkbox" name="colourchip[]" value="Primrose"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="Chromatic Blue"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="White"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="Light Wd/Grain"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="Med Wd/Grain"></td><td width="1" bgcolor="#696969"></td>
                      <td><input type="checkbox" name="colourchip[]" value="Dark Wd/Grain"></td><td width="1" ></td>
                    </tr>
                  </table>
                <input type="submit" value="submit" name="submit">
                </td>
              </tr>
            </table>
          </form>
<?php }
else { 
include(
'dbinfo.php');       

$status="pending";
$insert "INSERT INTO samples VALUES (
          '
$PHPSESSID',
           NOW(),
          '
$name',
          '
$address1',
          '
$address2',
          '
$address3',
          '
$postcode',
          '
$email',
          '
$colourchip[1]',
          '
$colourchip[2]',
          '
$colourchip[3]',
          '
$colourchip[4]',
          '
$colourchip[5]',
          '
$status')";
$result mysql_query($insert
or die(
"Query failed: " mysql_error());
mysql_close();

echo
" <span id='normal'>Thankyou. We have received your request, your samples will be dispatched immediadtely.</span>
        
            <table border='0' width='' align=''>
              <tr height='40'>
              </tr>
              <tr valign='top'>
                <td width='80'>
                </td>
                <td align='right'>
                <span id='normalBoldDom'>To:<Br></span><Br>
                </td>
                <td align='left'  width='200' ><br>
                <span id='normal'>
$name<br>
                
$address1<br>
                
$address2<br>
                
$address3<br>
                
$postcode<br>
                
$email</span>
                </td>
                <td width='400'>
                </td>
              </tr>
              <tr>
                <td>"
;
                for(
$i 0$i 5$i++)
{
$chip=($i+1);
  
              if (
$colourchip[$i]=="none selected") {echo"<div id=chip".$chip."><img src='images/sample14.gif' width='54' height='81'/></div>";}
      else if (
$colourchip[$i]=="Silver Mirror") {echo"<div id=chip".$chip."><img src='images/sample0.gif' width='54' height='81'/></div>";}
      else if (
$colourchip[$i]=="Dove White")    {echo"<div id=chip".$chip."><img src='images/sample1.gif' width='54' height='81'/></div>";}    
      else if (
$colourchip[$i]=="Flame Red")     {echo"<div id=chip".$chip."><img src='images/sample2.gif' width='54' height='81'/></div>";}
      else if (
$colourchip[$i]=="Orchard Green") {echo"<div id=chip".$chip."><img src='images/sample3.gif' width='54' height='81'/></div>";}
      else if (
$colourchip[$i]=="Ocean Blue")    {echo"<div id=chip".$chip."><img src='images/sample4.gif' width='54' height='81'/></div>";}
      else if (
$colourchip[$i]=="Metallic Blue") {echo"<div id=chip".$chip."><img src='images/sample5.gif' width='54' height='81'/></div>";}             
      else if (
$colourchip[$i]=="Titanium")      {echo"<div id=chip".$chip."><img src='images/sample6.gif' width='54' height='81'/></div>";}            
      else if (
$colourchip[$i]=="Sky Blue")      {echo"<div id=chip".$chip."><img src='images/sample7.gif' width='54' height='81'/></div>";}
      else if (
$colourchip[$i]=="Jet Black")     {echo"<div id=chip".$chip."><img src='images/sample8.gif' width='54' height='81'/></div>";}
      else if (
$colourchip[$i]=="Bordeaux")      {echo"<div id=chip".$chip."><img src='images/sample9.gif' width='54' height='81'/></div>";}
      else if (
$colourchip[$i]=="Fuschia")       {echo"<div id=chip".$chip."><img src='images/sample10.gif' width='54' height='81'/></div>";}
      else if (
$colourchip[$i]=="Lilac")         {echo"<div id=chip".$chip."><img src='images/sample11.gif' width='54' height='81'/></div>";}
      else if (
$colourchip[$i]=="Primrose")      {echo"<div id=chip".$chip."><img src='images/sample12.gif' width='54' height='81'/></div>";}
      else if (
$colourchip[$i]=="Chromatic Blue"){echo"<div id=chip".$chip."><img src='images/sample13.gif' width='54' height='81'/></div>";}
            }
            echo
'
                </td>
              </tr>       
            </table>'
;
 }
?> 
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr height="130">
  <td colspan="2">
  <img src="images/bottom.jpg" width="800" height="130">
  </td>
  </tr>
</table>
      
  </body>
</html>
hiptobesquare is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-04-2006, 01:21 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
This is normal behaviour - the POST data gets sent back if you refresh. A quick way round it would be to check the username and email for duplicate entries in the table and ignore the repost.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 01-05-2006, 05:48 PM
hiptobesquare's Avatar
Extreme Talker

Posts: 186
Location: London UK
Trades: 0
Thanks Oberon.

I changed the query to this and now it works:
PHP Code:
include('dbinfo.php');       

$check_for_previous_entrys="SELECT * FROM SAMPLES WHERE EMAIL = '$email'";
$reply=mysql_query($check_for_previous_entrys);
$repeat_entry=mysql_numrows($reply);
if (
$repeat_entry 1)
{

$status="pending";
$insert "INSERT INTO samples VALUES (
          '
$PHPSESSID',
           NOW(),
          '
$name',
          '
$address1',
          '
$address2',
          '
$address3',
          '
$postcode',
          '
$email',
          '
$colourchip[1]',
          '
$colourchip[2]',
          '
$colourchip[3]',
          '
$colourchip[4]',
          '
$colourchip[5]',
          '
$status')";
$result mysql_query($insert
or die(
"Query failed: " mysql_error());
mysql_close();

hiptobesquare is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to My form resubmits on refresh
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12391 seconds with 12 queries