NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Help with php code (textbox's depends on quantity entered)

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 07-19-2007, 06:51 PM THREAD STARTER               #1 (permalink)
Senior Member
 
killaklown's Avatar
Join Date: Oct 2003
Posts: 3,472
killaklown is a splendid one to beholdkillaklown is a splendid one to beholdkillaklown is a splendid one to beholdkillaklown is a splendid one to beholdkillaklown is a splendid one to beholdkillaklown is a splendid one to beholdkillaklown is a splendid one to beholdkillaklown is a splendid one to behold
 



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


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 Code:
<?
$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.''];
????: NamePros.com http://www.namepros.com/programming/352057-help-php-code-textboxs-depends-quantity.html
$surl $_POST['surl'.$sn.''];
$stags $_POST['stags'.$sn.''];
$scat $_POST['scategory'.$sn.''];
$sdesc $_POST['sdescription'.$sn.''];

if((
$name == "")||($ppemail == "")||($sname == "")||($surl == "")||($stags == "")||($scat == "")||($sdesc == ""))
????: NamePros.com http://www.namepros.com/showthread.php?t=352057
{
$n++;
echo
'You forgot something, go back!';
}else{
$n++;
echo
'Accepted';
}
}
?>
killaklown is offline  
Old 07-25-2007, 04:29 PM   #2 (permalink)
NamePros Regular
Join Date: May 2007
Posts: 285
proer is a jewel in the roughproer is a jewel in the roughproer is a jewel in the rough
 



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.
proer is offline  
Old 07-27-2007, 12:25 AM   #3 (permalink)
NamePros Member
Join Date: Feb 2007
Location: Surabaya - Indonesia
Posts: 27
silentwind is an unknown quantity at this point
 



...


Hope this help you.
PHP Code:
<?
    $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.''];
????: NamePros.com http://www.namepros.com/showthread.php?t=352057
        
$sdesc $_POST['sdescription'.$sn.''];
        
        if((
$name == "")||($ppemail == "")||($sname == "")||($surl == "")||($stags == "")||($scat == "")||($sdesc == ""))
????: NamePros.com http://www.namepros.com/showthread.php?t=352057
        {
            
$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
    
}
?>
__________________
-- Silent's Spot [blog]
-- Curriculum Vitae [CV]
silentwind is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 12:47 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger