Jump to content

I need some help on the form refresh submit


Recommended Posts

My problem is .. everytime when i click refresh on my broswer it adds another item to my databasewhat can i do to make it only adds the data to database by only clicking submiti think the problem i have is .. how do i check using an php If statement to see if an submit buttom is clicked also refresh will not count as a submit .. i know the post data will keep posting if refresh is clicked .. but how can I avoid that??

<html><body><form action="welcome.php" method="post"><table border='1'>  <tr>    <td>EnglishInfo: </td>    <td><input type="text" name="EnglishInfo" /></td>  </tr>  <tr>     <td>ChineseInfo: </td>     <td><input type="text" name="ChineseInfo" /></td>  </tr>  <tr>     <td>Links: </td>      <td><input type="text" name="Links" /> </td>  </tr></table><input type="submit" name="submit" value="clicked" /></form><?php$con = mysql_connect("localhost","******","********");if (!$con)  {  die('Could not connect: ' . mysql_error() );  }else{  mysql_select_db("chelvan_videos", $con);if(isset($_POST[submit])){   $result2 = mysql_query("SELECT MAX(FieldNumber) FROM videoscontrol");   $row = mysql_fetch_array($result2);   $field = $row['MAX(FieldNumber)'] + 1;   $sql = "INSERT INTO videoscontrol(FieldNumber, EnglishInfo, ChineseInfo, Links)    VALUES('$field', '$_POST[EnglishInfo]','$_POST[ChineseInfo]','$_POST[Links]')";   mysql_query($sql);}$result = mysql_query("SELECT * FROM videoscontrol ORDER BY FieldNumber");echo "<table border='1'><tr><th>FieldNumber</th><th>EnglishInfo</th><th>ChineseInfo</th><th>Links</th></tr>";while($row = mysql_fetch_array($result))  {  echo "<tr>";  echo "<td>" . $row['FieldNumber'] . "</td>";  echo "<td>" . $row['EnglishInfo'] . "</td>";  echo "<td>" . $row['ChineseInfo'] . "</td>";  echo "<td>" . $row['Links'] . "</td>";  echo "</tr>";  }echo "</table>";mysql_close($con);}?></body></html>
Link to post
Share on other sites

Hi..add this line @ the end of code after closing connection..use redirect funda whenever you face this type of probs..so page will be redirected after our db insertion process.. so it won't add if you refresh the page due to redirection...Regards,Vijay------------------------------------------------------------------------------------- ............ echo "<td>" . $row['EnglishInfo'] . "</td>"; echo "<td>" . $row['ChineseInfo'] . "</td>"; echo "<td>" . $row['Links'] . "</td>"; echo "</tr>"; }echo "</table>";mysql_close($con);header("location:welcome.php"); // this 2 lineexit; // this line also..}

Link to post
Share on other sites
Hi..add this line @ the end of code after closing connection..use redirect funda whenever you face this type of probs..so page will be redirected after our db insertion process.. so it won't add if you refresh the page due to redirection...Regards,Vijay------------------------------------------------------------------------------------- ............ echo "<td>" . $row['EnglishInfo'] . "</td>"; echo "<td>" . $row['ChineseInfo'] . "</td>"; echo "<td>" . $row['Links'] . "</td>"; echo "</tr>"; }echo "</table>";mysql_close($con);header("location:welcome.php"); // this 2 lineexit; // this line also..}
i added the 2 lines it still adds another line of data in the database when i click refresh
Link to post
Share on other sites
echo "<td>" . $row['EnglishInfo'] . "</td>"; echo "<td>" . $row['ChineseInfo'] . "</td>"; echo "<td>" . $row['Links'] . "</td>"; echo "</tr>"; }echo "</table>";mysql_close($con);header("location:welcome.php"); // this 2 lineexit; // this line also..}
that wouldn't work, you cannot modify headers after all those echo-s
Link to post
Share on other sites
Eh..I think he can. If he puts ob_start(); on top of the document (under session_start(); if you have that)
OK I added <?php session_start(); ob_start(); ?> <html> <body> ....... ....... // under my insert if() i added the header("location: welcome.php"); and it worked .. thanks
Link to post
Share on other sites

with output buffering you can put header() "anywhere" (almost, not after you flushed...) you want..Without OB, you must put it before any output

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...