Help with php code (textbox's depends on quantity entered)

Discussion in 'Programming' started by killaklown, Jul 19, 2007.

  1. #1
    Im trying to get this code to work. This is a checkout im working on for my site, the user selects a package and types in how much of those packages they want. If they type '1' it shows just the text boxes for 1. But if they choose '5' it shows those text boxes 5 times.

    IE:

    I choose '3' for the quantity. It will show:

    #1
    Site Name:
    Site Url:
    Etc:
    Etc:

    #2
    Site Name:
    Site Url:
    Etc:
    Etc:

    #3
    Site Name:
    Site Url:
    Etc:
    Etc:

    but the code i have will check #1, if all fields are present, it accepts it. Then it checks #2, if a field is present, it rejects it. Then #3 if all fields are present, it accepts it.

    I want it to reject ALL (ie #1 and #2 have all the fields present, but #3 is missing a field, then it rejects them all)

    
    <?
    $qty = $_POST['qnty'];
    $total = $_POST['cost'];
    $name = $_POST['name'];
    $ppemail = $_POST['email'];
    $pkg = $_POST['package'];
    
    while($n < $qty){
    $sn= $n + 1;
    $sname = $_POST['sname'.$sn.''];
    $surl = $_POST['surl'.$sn.''];
    $stags = $_POST['stags'.$sn.''];
    $scat = $_POST['scategory'.$sn.''];
    $sdesc = $_POST['sdescription'.$sn.''];
    
    if(($name == "")||($ppemail == "")||($sname == "")||($surl == "")||($stags == "")||($scat == "")||($sdesc == ""))
    {
    $n++;
    echo'You forgot something, go back!';
    }else{
    $n++;
    echo'Accepted';
    }
    }
    ?>
    
    PHP:

    Edit: can someone move this to the php section?
     
    killaklown, Jul 19, 2007 IP
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Dont do PHP but the logic for doing it is the same across any language

    Set a variable (eg ErrorTxT) before the while loop, go through the loop each time and if your if statement comes out as True then change the ErrorTxT to true, if the if statement comes back as false then leave the errortxt variable in its current state.

    After the loop do the You forgot/ Accepted element based on the value of ErrorTxT
     
    AstarothSolutions, Jul 20, 2007 IP
    killaklown likes this.
  3. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #3


    Thanks, had to do a little more too it because i wanted to add each quantity to a row with the data.
     
    killaklown, Jul 20, 2007 IP