Web Analytics Made Easy -
StatCounter Refresh adds new rows to the DB - CodingForum


No announcement yet.

Refresh adds new rows to the DB

  • Filter
  • Time
  • Show
Clear All
new posts

  • Refresh adds new rows to the DB

    Hello again everybody

    I've got a problem: each time I refresh the page containing the script below I'm actually adding a new row to the DB
    PHP Code:
    require_once ('../mysql_connect.php');

    if ( !empty(
    $zname) && !empty($player1) && !empty($player2) ) {
    $z escape_data($zname);
    $p1 escape_data($player1);
    $p2 escape_data($player2);
    } else {
    'The game could not be added because some fields were left empty.';
    $z FALSE;
    $p1 FALSE;
    $p2 FALSE;

    if (
    $z && $p1 && $p2) {
    $q "INSERT INTO...";
    $r mysql_query ($q1);
        if (
    mysql_affected_rows() == 1) {
    "Thank you for registering the game. Good Luck!";
        } else {    
    'Sorry, the game could not be added...';
    } else {
    'Please go back and try again.';

    Can somebody please drop me a hint on how it could be prevented?
    Thank you in advance
    Have a wonderful day

  • #2
    Depending on how you send the data (get or post)

    I will go with the POST method

    PHP Code:

    if ($_POST['submit'] == "button text") {
    // insert code here

    So, for that to work your button would look like

    PHP Code:
    <input type="submit" name="submit" value="button text" /> 
    This way, it will only work after the POST was called.

    I think..

    Hope this helps


    • #3
      Thank you for your answer, bfsog
      I have:
      <input type="Submit" name="register" value="Register!">
      And yep I actually forgot to add :
      PHP Code:
      if (isset($register)) {
          require_once (

      which looks much alike that you suggested... but neither works! Still if I refresh the page I'm adding new rows to the DB I may assume it is related to the fact that the form is on a different page and this page is only 'handling' the data that comes from the page containing the form...?
      Oh yeah and of course I've got:
      PHP Code:
      $zname $_POST['zname'];
      $player1 $_POST['player1'];
      $player2 $_POST['player2'];
      $register $_POST['register']; 
      at the beginning of the script that handles the form...