Results 1 to 7 of 7

Thread: Need a lil help with this

  1. #1

    Need a lil help with this

    I have a script that i need a little help with. I think ive got it correct but something is missing because when i go to run it it doesnt work the way it should.

    PHP Code:
    <?php
        
    if ( isset( $_POST['post'] ) )
        {
            
    $names $_POST['name'];
            
    $positions $_POST['position_id'];
            
    $i 1;
            
            foreach ( (
    $names as $name) && ($positions as $position_id) )
            {    
                
    $name trim($name);
                
    $value[$i] = $name;

                if ( !empty(
    $name) ) 
                {    
                    
    mysql_query'INSERT INTO players (player_id, player_name, position_id, team_id) VALUES ("","'.$name.'","'.$positions.'","1")');
                }

                ++
    $i;
            }
        }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Content-language" content="en-US" />
    <title></title>

    </head>
    <body>
        <form method="post" action="<?php echo $_SERVER['PHP_SELF'?>" >
            <ol>
                <?php
                    
    for ( $i 1$i <= 10; ++$i )
                    {
                
    ?>
                <li>
                    <label><span>Name</span> 
                        <input type="text" name="name[]" value="<?php echo $value[$i]; ?>" />    
                    </label>
                    <label><span>Position</span>
                                <select name="position_id[]" id="position">
                  <option value="1">Manager</option>
                  <option value="2" selected="selected">Pitcher</option>
                  <option value="3">Catcher</option>
                  <option value="4">1st Base</option>
                  <option value="5">2nd Base</option>
                  <option value="6">Short Stop</option>
                  <option value="7">3rd Base</option>
                  <option value="8">left Field</option>
                  <option value="9">Center Field</option>
                  <option value="10">Right Field</option>
                  <option value="11">DH</option>
                            </select>

                    </label>

                <?php
                    
    }
                
    ?>
            </ol>
            <input type="submit" name="post" value="Submit" />
        </form>
    </body>
    </html>
    what it is not doingis adding the position number in the insert query infarct it is ignoring it all together..

    any ideas what im doing worng?

  2. #2
    First thing I see is your writing:
    PHP Code:
     ++$i 
    When the proper method is:
    PHP Code:
    $i++ 

  3. #3
    yes bit it works either way and i know that is not the problem. ill go in and fix. thanks for the tip.

  4. #4
    Quote Originally Posted by webreforms View Post
    First thing I see is your writing:
    PHP Code:
     ++$i 
    When the proper method is:
    PHP Code:
    $i++ 
    Nope, this only makes a difference when echo'ing.
    PHP Code:
    $i 0;
    echo ++
    $i//outputs 1
    echo $i++; //outputs 1
    echo $i//outputs 2 
    Web Design and Web Development blog
    Designer Notice: Browser List for design compatibility

  5. #5
    thanks for the tips but my problem is that when i hit the submit button the names get posted to the database but the position id does not. can any one see why its not doing what it is suposed to be doing?

  6. #6
    my script , which I can see what you've done wrong. i can fix it... but where's my money

    I can lead you in the right direction... in saying that this line
    PHP Code:
    foreach ( ($names as $name) && ($positions as $position_id) ) 
    won't work, and you should be getting error that tells you that

    off topic:
    -------------------------


    also, while

    PHP Code:
    $i++ 
    and
    PHP Code:
    ++$i 
    are essentially the same, the only reason I use ++$i (which is why it's in the code above since I did that too) is cause it's fractions of a second faster than $i++. anything to optimize is good

    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  7. #7
    thanks for the push in the rite direction. ill look over it again and see what i come up with.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012