Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Location
    Ireland
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How Do I grab a parameter from php form and send it to a script

    I am developing a script to up date League tables for a football site,
    I start with a link to the update form with start.php?divisions_id=the selected division,
    this is used to populate two list boxs with teams for the selected divisions with
    $div_id = (isset($_GET['divisions_id'])) ? $_GET['divisions_id'] : false;
    $query = 'SELECT team_id, team_name from teams where divisions_id = ' . $div_id;
    Works perfectly so far.

    the process.php carries out the form processing this works fine too
    To develop the script further I need some help,
    No 1
    I need to pass the division_id to the process form as the same
    team names will be used in different divisions ,can I extract the division_id from the $_Get
    and pass it on to the process form ? or how could I accomplish this.

    No 2
    In the update if Team A scores 1 Goal and Team B Scores 2 goals the database updates Perfectly
    how ever if either team has a zero score "0" the database does not update anything,
    this only happens if the team has no previous entrys or the DB fields contain zero "0" or a null value.
    I imagine its because 0 + 0 = nothing, how can I work around this.
    =============
    I have attached the code as a text file
    Thank you Mick

    file.txt
    Last edited by mick104; 08-30-2006 at 05:01 PM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts

    Post

    On your first issue you have a few options how to send data from PHP script to PHP script:

    1. Stuff values into the url and then use the $_GET array.
    2. Use hidden input fields in your form, assign a value to the hidden field and then use the $_POST array in process.php.
    3. Set a cookie in start.php, then read the cookie in process.php.
    4. Use sessions and set a $_SESSION variable in start.php, then read the $_SESSION variable in process.php.

    I would recommend #1 or #2.

    On your second issue, I think it is these "if" statements that are causing you grief:
    PHP Code:
    //Add total Goals_For
    if ($goals_for $goals_for $goal_b )

        
    //Add total Goals_against
        
    if ($goals_against $goals_against $goal_a )

            
    // update records for team (b)
            
    $query "UPDATE teams
            SET games_played = '$games_played',
            wins = '$wins',
            draw='$draw',
            loses='$loses',
            league_points='$league_points',
            goals_for='$goals_for',
            goals_against='$goals_against'
            WHERE team_name = '$team_b'"
    ;

    mysql_query($query) or die ("Failed to update team B<br>Debug info: $query");
    echo 
    "<b>Sucesfully updated Leage Table</b>"
    I've properly indented the code block. You can see the only thing inside your "if" block is the $query assignment. They call to mysql_query() is outside of it. You need to use brackets {} to contain your ifs.

    PHP Code:
    //Add total Goals_For
    if ($goals_for $goals_for $goal_b ) {

        
    //Add total Goals_against
        
    if ($goals_against $goals_against $goal_a ) {

            
    // update records for team (b)
            
    $query "UPDATE teams
            SET games_played = '$games_played',
            wins = '$wins',
            draw='$draw',
            loses='$loses',
            league_points='$league_points',
            goals_for='$goals_for',
            goals_against='$goals_against'
            WHERE team_name = '$team_b'"
    ;

            
    mysql_query($query) or die ("Failed to update team B<br>Debug info: $query");
            echo 
    "<b>Sucesfully updated Leage Table</b>";
        }


  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Location
    Ireland
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem Sorted for php league tables

    Thanks For your help Fumigator
    Resolution for Q 1 hidden field in the start form,
    $div_id had already been passed to this form through the url
    PHP Code:
    $div_id = (isset($_GET['divisions_id'])) ? $_GET['divisions_id'] : false
    planted it in a hidden field like you suggested,
    PHP Code:
    <input type="hidden" name="div_id" value="<?= $div_id ?>" />
    Picked it up in the process.php
    PHP Code:
    if(isset($_POST['$div_id'])){ 
    $div_ref $_POST['$div_id']; } 
    Attached it to,
    PHP Code:
    WHERE team_name ='$team_a'AND divisions_id =$div_id"; 
    to my SELECT and UPDATE statements.
    Works like a dream.
    Resolution for Q 2 "if" statements were causing my grief:
    I added the brackets like you suggested but this did not solve the problem except for a good lesson in formatting my code properly thank you,
    while adding the brackets to the "ifs" I noted,
    PHP Code:
    if ($goals_for $goals_for $goal_b )  
    if (
    $goals_against $goals_against $goal_a 
    I did not need Ifs here so I changed it to,
    PHP Code:
    $goals_for $goals_for $goal_a;
    $goals_against $goals_against $goal_b
    problem sorted
    Thanks again Fumigator

    Next Question (you thought I was finished ha )
    I want to add an other dropdown list to the start.php form
    this will select round 1,round 2,simi final and so on,
    I have game_id and game_name.
    what I want to do is view the game_name in the listbox (ie Simi Final) but send the game_id (numeric value) to the DB table.
    Any Ideas for this one, heres the code for the list box
    PHP Code:
    <?php
    $query 
    'SELECT game_id, game_name from game ';
       
    $result mysql_query($query) or die(mysql_error());
    if (
    $result)
       {
       echo 
    "<SELECT NAME='game_id'>";
       while (
    $row mysql_fetch_array($result))
          {
          echo 
    "<OPTION VALUE=\"".$row["game_name"]."\">".
               
    $row["game_name"]."</OPTION> ";
          }
       echo 
    "</SELECT>";
       }
    ?>

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You can use the "value" parameter of your select tags to store the game ID, while still displaying game_name in the list box.

    <option value="12345">name of game</option>

    The value of your $_POST['game_id'] (the list box value) will be 12345 when the form is submitted.


  •  

    Posting Permissions

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