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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem passing $_POST Values from Form

    I'm working on creating a gaming ladder for a tournament I'm in charge of. I'm having some trouble with getting the post values from a form after it has been submitted. Here is the link to the page...

    http://gulfcoastcommandos.freehostia...geposition.php

    Everything comes up fine, but as soon as you try to submit it, all the positions in the database are set to 0 (zero). I believe I have narrowed it down to the
    PHP Code:
    $newpos=$_POST['$teamname'
    line because in on the next page, it displays "Team Name: ... Position: "with nothing following position(no number, no text).

    Here is the code for the place where the admin can make the changes to the team position. Everything on this page displays and works appropriately (except the POST passing of values). You'll have to trust me on this because as soon as someone here goes and tries to change them, this page no longer works since all team positions are 0.

    PHP Code:
    <?php
    include("include/logincheck.php");
    include(
    "include/header.php");
    include(
    "include/connect.php");
    include(
    "include/admincheck.php");
    ?>
    <div align="center" class="style7">
    <br><br>
    Adjust the order of the teams by selecting a new number in the box.<br><br>
    <form action="processchangeposition.php" method="POST">
    <table width="40%">
    <?php

    //get the maximum position from the database
    $query="SELECT position FROM team";
    $result=mysql_query($query)
        or die(
    "Database is unreachable.  Contact an administrator or try again in a few minutes.");
    while (
    $row=mysql_fetch_assoc($result))
    {
        
    extract($row);
        if (
    $position>$maxpos)
        {
            
    $maxpos=$position;
        }
    }

    //get all the team names and positions
    $query="SELECT name, position FROM team ORDER BY position";
    $result=mysql_query($query)
        or die(
    "Error connecting to database");

    //cycle through the array of teams and make an option to change the position of each team based on the $maxpos variable
    while ($row=mysql_fetch_assoc($result))
    {
        
    extract($row);
        
    //create different drop-down select for each team
        
    echo "<tr>
                <td class='style7'>$name</td>
                <td class='style7'><select name='$name'>"
    ;
                for (
    $a=1;$a<=$maxpos;$a++)
                {
                    if (
    $position==$a)
                    {
                        echo 
    "<option value='$a' selected='selected'>$a";
                    }
                    else
                    {
                        echo 
    "<option value='$a'>$a";
                    }
                }
              echo 
    "</select></td></tr>";
    }
    ?>

    <tr>
        <td class="style7" colspan="2" align="center"><input type="submit" value="Submit Changes"></td>
    </tr>
    </table>
    </form>
    </div>
    <?php
    include("include/footer.php");
    ?>

    Here is the code for what happens to process the change
    PHP Code:
    <?php
    include("include/logincheck.php");
    include(
    "include/header.php");
    include(
    "include/connect.php");
    include(
    "include/admincheck.php");
    ?>
    <div align="center" class="style7">
    <?php
    //cycle through all the teams in the database
    $query="SELECT name FROM team ORDER BY position";
    $result=mysql_query($query)
        or die(
    "Error connecting to database");
    while (
    $row=mysql_fetch_assoc($result))
    {
        
    //get the team name from the database
        
    $teamname=$row['name'];
        
    //get the position from the POST variable - NOT WORKING!!!
        
    $pos=$_POST['$teamname'];
        
        echo 
    "Name: $teamname Position: $pos <br>";
        
    //update the database for each team
        
    $query1="UPDATE team SET position='$pos' WHERE name='$teamname'";
        
    $result1=mysql_query($query1)
            or die(
    "Error connecting to database");
    }
    ?>
    <br><br>
    Team positions changed successfully.
    </div>
    <?php
    include("include/footer.php");
    ?>
    Thank you in advance for your help.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Change $newpos=$_POST['$teamname']

    to $newpos=$_POST['teamname']
    (Just a quick look, hope this may help!)
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not sure that is correct because...
    Code:
    <select name='$name'>
    The name of the select fields is not "teamname" it's the actual name of the team.

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    $newpos=$_POST['$teamname']
    Actually, that would be the problem.

    Single quotes do not have their variables parsed.

    So if $teamname is the name of the team, and the dropdown has that name, then you'd want this:

    PHP Code:
    $newpos=$_POST[$teamname

  • #5
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for your help. That fixed part of the problem.

    It still isn't completely successful and I think it is because the team names have spaces. Is there a way to get rid of the spaces(just for setting the name attribute)? Or is there a better way than my current system?

  • #6
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,083
    Thanks
    2
    Thanked 23 Times in 23 Posts
    This is just a guess since I don't know your database schema, but how about changing team name to an id in your form? Your script could then look up the team name by id, then do subsequent processing based on that.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!


  •  

    Posting Permissions

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