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 3 of 3

Thread: checkboxes

  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Location
    Illinois
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    checkboxes

    Hello,

    I am in the middle of putting together a Nascar fantasy racing site. I am new to php, so I couldn't create the script so I paid Cory Schoop to get the job done. He has done VERY well, but I told him wrong at the beginning, and now I am trying to fix it. Instead of having 8 drop down menus to select your drivers I wanted each driver to have a check box, and have them select 8 drivers that way. This would prevent someone picking two of the same driver. If you have a better way with drop down menus to stop people from selecting the same driver two times, I would be happy to hear it also. Anyways, I have tried to modify the code, but its not exactly working. I will attach both the original, and my attempt to change it. On mine each driver, no matter who you choose is put into the database as "0". Each driver is assigned a value, and "0" is nobody, so that obviously is not working. Anyways, here is the code:

    This is my editted version that does not work.

    PHP Code:
    function saveteam($submit$teamname$first$last$address$city$state$zip$email$driver ) {
        
        
    connection();
        print(
    "<a href=index.php>Main Menu - saveteam</a><br><br>");

        if(
    $submit)    
        {
            
    // VALIDATE DATA
            
    $goahead 'yes';$onceonly='0';
            for(
    $x=1;$x<=8;$x++)
            {
            if(
    $driver[$x]=='foo')
                {
    $goahead 'no';
                if(
    $onceonly=='0'){print("Please select " count($driver) . " drivers<br>");$onceonly='1';}
                }
            }
            if(
    strlen($teamname) < || strlen($teamname) > 15)
            {
                 print 
    'Your Team Name must contain 4 to 15 characters.<br>';
            
    $goahead 'no';
            }
            if(!
    preg_match('/^[A-Za-z0-9 \_]+$/',$teamname))
            {
             print 
    'Your Team Name can only contain the following: capital letters, lower case letters, 0-9 numbers, space, the underscore<br>';
            
    $goahead 'no';
            }
            if(
    strlen($first) < || strlen($first) > 15)
            {
                 print 
    'Your First Name can only contain 4 to 15 characters.<br>';
            
    $goahead 'no';
            }
            if(!
    preg_match("/[A-Za-z]+/",$first))
            {
                 print 
    'Your First Name may only contain capital letters and lower case letters.<br>';
            
    $goahead 'no';
            }
            if(
    strlen($address) < || strlen($address) > 100)
            {
                 print 
    'Your Address can only contain 5 to 20 characters.<br>';
            
    $goahead 'no';
            }
            if(
    strlen($city) < || strlen($city) > 20)
            {
                 print 
    'Your City can only contain 1 to 20 characters.<br>';
            
    $goahead 'no';
            }
            if(!
    preg_match('/^[A-Za-z]+$/',$city))
            {
                 print 
    'Your City may only contain capital letters and lower case letters.<br>';
            
    $goahead 'no';
            }
            if(
    strlen($zip) < || strlen($zip) > 10)
            {
                 print 
    'Your Zip Code can only contain 5 to 10 characters.<br>';
            
    $goahead 'no';
            }
            if(!
    preg_match('/^[0-9 \-]+$/',$zip))
            {
                 print 
    'Your Zip Code may only contain numbers 0-9 and the hyphen.<br>';
            
    $goahead 'no';
            }
            if(!
    preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*?[a-z]+$/is',$email))
            {
                 print 
    'Your E-mail is invalid.<br>';
            
    $goahead 'no';
            }
            
    // this is the check for the salary cap
            
    if( !check_salary_cap($driver) ){ 
                
    $goahead 'no';
            }
            if(
    $goahead == 'no'){print("<br><br>Please press back and try again<br>");die;}
            
    // END DATA VALIDATION

        // INSERT THE RECORD
        
    $query_next_id "SELECT id FROM teams ORDER BY id DESC";
        
    $query_next_id_res mysql_query($query_next_id);
        
    $next_id_row mysql_fetch_array($query_next_id_resMYSQL_ASSOC);
        
    $the_next_id $next_id_row["id"]+1;

        
    //echo "NEXT ID: " . $the_next_id;
        
    $query "insert into teams values('$the_next_id', '$teamname', '$first', '$last', '$address', '$city', '$state', '$zip', '$email', '', 
        '$driver[0]', '$driver[1]','$driver[2]', '$driver[3]', '$driver[4]', '$driver[5]', '$driver[6]', '$driver[7]')"


        
    //echo "<br />" . $query;
        
    mysql_query($query);

        
    $query_team_points "INSERT INTO teampoints VALUES ('$the_next_id', '$teamname', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)";
        
    mysql_query($query_team_points);
        
    //echo $query_team_points;

        // PRINT A HAPPY MESSAGE
        
    print("Thanks a lot man for inserting that team<br>");

        }    
    // end of saveteam
    //****************************************************************************

    function addteam() {
        
    connection();
        print(
    "<a href=index.php>Main Menu - addteam</a><br><br>");
        print(
    "

        <html>
        <body>

        Please fill in all required fields!
          <form method=\"post\" action=\"saveteam.php\">
          Team Name:<input type=\"Text\" name=\"teamname\"><br> 
          First Name:<input type=\"Text\" name=\"first\"><br> 
          Last Name:<input type=\"Text\" name=\"last\"><br>
          Address:<input type=\"Text\" name=\"address\"><br>
          City:<input type=\"Text\" name=\"city\"><br>
          State:<select name=\"state\">
        "
    );

        
    // I KNOW THIS WAS ****TY WAY TO DO STATES BUT I ALREADY HAD THIS ARRAY
        
    $abbrev_array[] = "AL";$abbrev_array[] = "AK";$abbrev_array[] = "AZ";$abbrev_array[] = "AR";$abbrev_array[] = "CA";$abbrev_array[] = "CO";$abbrev_array[] = "CT";$abbrev_array[] = "DE";$abbrev_array[] = "FL";$abbrev_array[] = "GA";$abbrev_array[] = "HI";$abbrev_array[] = "ID";$abbrev_array[] = "IL";$abbrev_array[] = "IN";$abbrev_array[] = "IA";$abbrev_array[] = "KS";$abbrev_array[] = "KY";$abbrev_array[] = "LA";$abbrev_array[] = "ME";$abbrev_array[] = "MD";$abbrev_array[] = "MA";$abbrev_array[] = "MI";$abbrev_array[] = "MN";$abbrev_array[] = "MS";$abbrev_array[] = "MO";$abbrev_array[] = "MT";$abbrev_array[] = "NE";$abbrev_array[] = "NV";$abbrev_array[] = "NH";$abbrev_array[] = "NJ";$abbrev_array[] = "NM";$abbrev_array[] = "NY";$abbrev_array[] = "NC";$abbrev_array[] = "ND";$abbrev_array[] = "OH";$abbrev_array[] = "OK";$abbrev_array[] = "OR";$abbrev_array[] = "PA";$abbrev_array[] = "RI";$abbrev_array[] = "SC";$abbrev_array[] = "SD";$abbrev_array[] = "TN";$abbrev_array[] = "TX";$abbrev_array[] = "UT";$abbrev_array[] = "VT";$abbrev_array[] = "VA";$abbrev_array[] = "WA";$abbrev_array[] = "WV";$abbrev_array[] = "WI";$abbrev_array[] = "WY";

        for(
    $s=0;$s<count($abbrev_array);$s++)
        {print(
    "<option>$abbrev_array[$s]</option>");}

        print(
    "</select>
        <br>
          Zip Code:<input type=\"Text\" name=\"zip\"><br>
          Email:<input type=\"Text\" name=\"email\"><br>
        "
    );

            
            {
            
    // The value here ties in to the driver id for the database tables.    
            
    print("
        
                Please select 8 Drivers:<br>
                <input type=\"checkbox\" name=\"jgordon\" value=\"1\">Jeff Gordon #24
                <input type=\"checkbox\" name=\"rwallace\" value=\"2\">Rusty Wallace #2
                <input type=\"checkbox\" name=\"mkenseth\" value=\"3\">M. Kenseth #17
                <input type=\"checkbox\" name=\"tstewart\" value=\"4\">T. Stewart #20
                <input type=\"checkbox\" name=\"mmartin\" value=\"5\">M. Martin #6
                <input type=\"checkbox\" name=\"blabonte\" value=\"6\">B. Labonte #18
                <input type=\"checkbox\" name=\"tlabonte\" value=\"7\">T. Labonte #5
                <input type=\"checkbox\" name=\"djarret\" value=\"8\">D. Jarret #88




    <br>
            "
    );
            
            } 
    // end of the for
        
        
    print("
          <input type=\"Submit\" name=\"submit\" value=\"Enter information\">
          </form>
        </body>
        </html>
        "
    );

    Here is the original version.

    PHP Code:

    function saveteam($submit$teamname$first$last$address$city$state$zip$email$driver ) {
        
        
    connection();
        print(
    "<a href=index.php>Main Menu - saveteam</a><br><br>");

        if(
    $submit)    
        {
            
    // VALIDATE DATA
            
    $goahead 'yes';$onceonly='0';
            for(
    $x=1;$x<=8;$x++)
            {
            if(
    $driver[$x]=='foo')
                {
    $goahead 'no';
                if(
    $onceonly=='0'){print("Please select " count($driver) . " drivers<br>");$onceonly='1';}
                }
            }
            if(
    strlen($teamname) < || strlen($teamname) > 15)
            {
                 print 
    'Your Team Name must contain 4 to 15 characters.<br>';
            
    $goahead 'no';
            }
            if(!
    preg_match('/^[A-Za-z0-9 \_]+$/',$teamname))
            {
             print 
    'Your Team Name can only contain the following: capital letters, lower case letters, 0-9 numbers, space, the underscore<br>';
            
    $goahead 'no';
            }
            if(
    strlen($first) < || strlen($first) > 15)
            {
                 print 
    'Your First Name can only contain 4 to 15 characters.<br>';
            
    $goahead 'no';
            }
            if(!
    preg_match("/[A-Za-z]+/",$first))
            {
                 print 
    'Your First Name may only contain capital letters and lower case letters.<br>';
            
    $goahead 'no';
            }
            if(
    strlen($address) < || strlen($address) > 100)
            {
                 print 
    'Your Address can only contain 5 to 20 characters.<br>';
            
    $goahead 'no';
            }
            if(
    strlen($city) < || strlen($city) > 20)
            {
                 print 
    'Your City can only contain 1 to 20 characters.<br>';
            
    $goahead 'no';
            }
            if(!
    preg_match('/^[A-Za-z]+$/',$city))
            {
                 print 
    'Your City may only contain capital letters and lower case letters.<br>';
            
    $goahead 'no';
            }
            if(
    strlen($zip) < || strlen($zip) > 10)
            {
                 print 
    'Your Zip Code can only contain 5 to 10 characters.<br>';
            
    $goahead 'no';
            }
            if(!
    preg_match('/^[0-9 \-]+$/',$zip))
            {
                 print 
    'Your Zip Code may only contain numbers 0-9 and the hyphen.<br>';
            
    $goahead 'no';
            }
            if(!
    preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*?[a-z]+$/is',$email))
            {
                 print 
    'Your E-mail is invalid.<br>';
            
    $goahead 'no';
            }
            
    // this is the check for the salary cap
            
    if( !check_salary_cap($driver) ){ 
                
    $goahead 'no';
            }
            if(
    $goahead == 'no'){print("<br><br>Please press back and try again<br>");die;}
            
    // END DATA VALIDATION

        // INSERT THE RECORD
        
    $query_next_id "SELECT id FROM teams ORDER BY id DESC";
        
    $query_next_id_res mysql_query($query_next_id);
        
    $next_id_row mysql_fetch_array($query_next_id_resMYSQL_ASSOC);
        
    $the_next_id $next_id_row["id"]+1;

        
    //echo "NEXT ID: " . $the_next_id;
        
    $query "insert into teams values('$the_next_id', '$teamname', '$first', '$last', '$address', '$city', '$state', '$zip', '$email', '', 
        '$driver[0]', '$driver[1]','$driver[2]', '$driver[3]', '$driver[4]', '$driver[5]', '$driver[6]', '$driver[7]')"


        
    //echo "<br />" . $query;
        
    mysql_query($query);

        
    $query_team_points "INSERT INTO teampoints VALUES ('$the_next_id', '$teamname', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)";
        
    mysql_query($query_team_points);
        
    //echo $query_team_points;

        // PRINT A HAPPY MESSAGE
        
    print("Thanks a lot man for inserting that team<br>");

        }    
    // end of saveteam
    //****************************************************************************

    function addteam() {
        
    connection();
        print(
    "<a href=index.php>Main Menu - addteam</a><br><br>");
        print(
    "

        <html>
        <body>

        Please fill in all required fields!
          <form method=\"post\" action=\"saveteam.php\">
          Team Name:<input type=\"Text\" name=\"teamname\"><br> 
          First Name:<input type=\"Text\" name=\"first\"><br> 
          Last Name:<input type=\"Text\" name=\"last\"><br>
          Address:<input type=\"Text\" name=\"address\"><br>
          City:<input type=\"Text\" name=\"city\"><br>
          State:<select name=\"state\">
        "
    );

        
    // I KNOW THIS WAS ****TY WAY TO DO STATES BUT I ALREADY HAD THIS ARRAY
        
    $abbrev_array[] = "AL";$abbrev_array[] = "AK";$abbrev_array[] = "AZ";$abbrev_array[] = "AR";$abbrev_array[] = "CA";$abbrev_array[] = "CO";$abbrev_array[] = "CT";$abbrev_array[] = "DE";$abbrev_array[] = "FL";$abbrev_array[] = "GA";$abbrev_array[] = "HI";$abbrev_array[] = "ID";$abbrev_array[] = "IL";$abbrev_array[] = "IN";$abbrev_array[] = "IA";$abbrev_array[] = "KS";$abbrev_array[] = "KY";$abbrev_array[] = "LA";$abbrev_array[] = "ME";$abbrev_array[] = "MD";$abbrev_array[] = "MA";$abbrev_array[] = "MI";$abbrev_array[] = "MN";$abbrev_array[] = "MS";$abbrev_array[] = "MO";$abbrev_array[] = "MT";$abbrev_array[] = "NE";$abbrev_array[] = "NV";$abbrev_array[] = "NH";$abbrev_array[] = "NJ";$abbrev_array[] = "NM";$abbrev_array[] = "NY";$abbrev_array[] = "NC";$abbrev_array[] = "ND";$abbrev_array[] = "OH";$abbrev_array[] = "OK";$abbrev_array[] = "OR";$abbrev_array[] = "PA";$abbrev_array[] = "RI";$abbrev_array[] = "SC";$abbrev_array[] = "SD";$abbrev_array[] = "TN";$abbrev_array[] = "TX";$abbrev_array[] = "UT";$abbrev_array[] = "VT";$abbrev_array[] = "VA";$abbrev_array[] = "WA";$abbrev_array[] = "WV";$abbrev_array[] = "WI";$abbrev_array[] = "WY";

        for(
    $s=0;$s<count($abbrev_array);$s++)
        {print(
    "<option>$abbrev_array[$s]</option>");}

        print(
    "</select>
        <br>
          Zip Code:<input type=\"Text\" name=\"zip\"><br>
          Email:<input type=\"Text\" name=\"email\"><br>
        "
    );

            for(
    $y=1;$y<=8;$y++)
            {
            
    // The value here ties in to the driver id for the database tables.    
            
    print("
          Driver #$y:<select name=\"driver[]\">
                <option value=foo>Select Driver</option>
                <option value=\"1\">Jeff Gordon #24</option>
                <option value=\"2\">R. Wallace #2</option>
                <option value=\"3\">M. Kenseth #17</option>
                <option value=\"4\">T. Stewart #20</option>
                <option value=\"5\">M. Martin #6</option>
                <option value=\"6\">B. Labonte #18</option>
                <option value=\"7\">T. Labonte #5</option>
                <option value=\"8\">D. Jarret #88</option>
                <option value=\"9\">Cory</option>
                </select><br>
            "
    );
            
            } 
    // end of the for
        
        
    print("
          <input type=\"Submit\" name=\"submit\" value=\"Enter information\">
          </form>
        </body>
        </html>
        "
    );


    Also, for testing purposes there are only 8 drivers on there. Once I get it to work, there will be around 50.

    Thanks everyone! Would love to hear any ideas if you think I am going about this wrong.

    Bye

  • #2
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    845
    Thanks
    15
    Thanked 10 Times in 10 Posts
    Origional
    PHP Code:
          Driver #$y:<select name=\"driver[]\">
                
    <option value=foo>Select Driver</option>
                <
    option value="1\">Jeff Gordon #24</option>
                <option value=\"2\">R. Wallace #2</option>
                <option value=\"3\">M. Kenseth #17</option>
                <option value=\"4\">T. Stewart #20</option>
                <option value=\"5\">M. Martin #6</option>
                <option value=\"6\">B. Labonte #18</option>
                <option value=\"7\">T. Labonte #5</option>
                <option value=\"8\">D. Jarret #88</option>
                <option value=\"9\">Cory</option>
                </select><br>
            "
    ); 
    Try this one... Let me know if it works.

    PHP Code:
        
    Please select 8 Drivers
    :<br>
    <
    input type="checkbox\" name=\"drivers\" value=\"1\">Jeff Gordon #24
    <input type=\"checkbox\" name=\"drivers\" value=\"2\">Rusty Wallace #2
    <input type=\"checkbox\" name=\"drivers\" value=\"3\">M. Kenseth #17
    <input type=\"checkbox\" name=\"drivers\" value=\"4\">T. Stewart #20
    <input type=\"checkbox\" name=\"drivers\" value=\"5\">M. Martin #6
    <input type=\"checkbox\" name=\"drivers\" value=\"6\">B. Labonte #18
    <input type=\"checkbox\" name=\"drivers\" value=\"7\">T. Labonte #5
    <input type=\"checkbox\" name=\"drivers\" value=\"8\">D. Jarret #88 
    I don't know if this will work but might.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    Driver #$y:<select name=\"driver[]\" multiple=\"multiple\" size=\"8\">
    
                <option value=foo>Select Driver</option>
    
                <option value="1\">Jeff Gordon #24</option>
    
                <option value=\"2\">R. Wallace #2</option>
    
                <option value=\"3\">M. Kenseth #17</option>
    
                <option value=\"4\">T. Stewart #20</option>
    
                <option value=\"5\">M. Martin #6</option>
    
                <option value=\"6\">B. Labonte #18</option>
    
                <option value=\"7\">T. Labonte #5</option>
    
                <option value=\"8\">D. Jarret #88</option>
    
                <option value=\"9\">Cory</option>
    
                </select><br>
    
            ");
    that'll do it.
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)


  •  

    Posting Permissions

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