SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to account for a user re-entering information

    I have a form where a users inputs goalscorers for each from a set of dropdown boxes. Any particular player can be selected more than one time (if they have scored multiple goals).

    Everything works as desired, however, how can I program the below code to account for the fact the user may revisit the form and re-enter the stats? As you can see in the code it takes each posted player increments the goals for that game by 1. If a user decides they have done it wrong and wants to re-enter the information, the goal amount for the player will contain the old data PLUS the new data. I dont know how to distinguish if a user is re-entering info, as if a user has scored more than one goal it will have to update the field and increment the field by 1, so I cant say ON DUPLICATE "drop data".

    PHP Code:
                foreach($_POST["opthm$value"] as $idx => $player) {
                        
    $sqlinsertscorersh= ('INSERT into stats SET
                        match_id = \''
    .$_SESSION['gmid'.$value].'\',
                        player_id = \''
    .$player.'\',
                        goals=(goals+1)
                        ON DUPLICATE KEY UPDATE
                        match_id = \''
    .$_SESSION['gmid'.$value].'\',
                        player_id = \''
    .$player.'\',
                        goals=(goals+1)'
    );
                        
    mysql_query($sqlinsertscorersh) or die(mysql_error()); }

        foreach(
    $_POST["optvis$value"] as $idx => $player) {
                        
    $sqlinsertscorersv= ('INSERT into stats SET
                        match_id = \''
    .$_SESSION['gmid'.$value].'\',
                        player_id = \''
    .$player.'\',
                        goals=(goals+1)
                        ON DUPLICATE KEY UPDATE
                        match_id = \''
    .$_SESSION['gmid'.$value].'\',
                        player_id = \''
    .$player.'\',
                        goals=(goals+1)'
    );
                        
    mysql_query($sqlinsertscorersv) or die(mysql_error()); } 
    Would the best way to do this just somehow block the user from revisiting the page once it is already entered (have a flag field in the database) and then create a seperate page they can to with the same code but drop all the data first?

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Have a login system (more work but reliable) or cookie (less reliable but easy and delicious)

  3. #3
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would that help me with this though? I am already using sessions, but other than creating two different pages and locking off the inputstats page for that week, im not sure how to do it.

  4. #4
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any ideas?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •