Help with Php code (textboxes depends on quantity entered)

SpaceshipSpaceship
Watch
Impact
11
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)

PHP:
<?
$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';
}
}
?>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains — AI StorefrontUnstoppable Domains — AI Storefront
I'm not sure if I understand when you want to stop the check(sorry, I'm still learning english), but maybe this will help :

Code:
  <?
$qty = $_POST['qnty'];
$total = $_POST['cost'];
$name = $_POST['name'];
$ppemail = $_POST['email'];
$pkg = $_POST['package'];

// For security, check the type and the content of the above vars before going further...

$n=0; // You should set a value to all the vars
         // Look if you have to set $n to 0 or 1

while($n < $qty){
 // you needn't $sn, don't create vars when you don't need them :-)

$sname = $_POST['sname'.$n.''];
$surl = $_POST['surl'.$n.''];
$stags = $_POST['stags'.$n.''];
$scat = $_POST['scategory'.$n.''];
$sdesc = $_POST['sdescription'.$n.''];

if(($name == "")||($ppemail == "")||($sname == "")||($surl == "")||($stags == "")||($scat == "")||($sdesc == ""))
{
  echo 'You forgot something, go back!';
  $n=$qty; // a clean way to exit the while loop. Other method : exit();

}else{

echo 'Accepted';
++$n; // next one, please
}
}
?>

I didn't check it.
 
0
•••
...

Hope this help you.
PHP:
<?
    $qty = $_POST['qnty'];
    $total = $_POST['cost'];
    $name = $_POST['name'];
    $ppemail = $_POST['email'];
    $pkg = $_POST['package'];
    
    $err = array();
    
    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 == ""))
        {
            $err[] = $sn;
        }else{
            $continue = true;
        }
        $n++;
    }
    if(sizeof($err) > 0){
        echo "Item No : " . implode(', ', $err) . " is invalid. Please repair it first.";
        //do repair code here
    }else{
        //do next code here
    }
?>
 
0
•••
Appraise.net

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomainEasy — Payment Flexibility
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back