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

Announcement

Collapse
No announcement yet.

Refresh adds new rows to the DB

Collapse
X
 
  • 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 {
        echo 
    '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) {
            echo 
    "Thank you for registering the game. Good Luck!";
        } else {    
            echo 
    'Sorry, the game could not be added...';
        }
        
    } else {
        echo 
    '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:
    <?php

    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

    Comment


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

      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...

      Comment

      Working...
      X