| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: Oct 2003
Posts: 3,472
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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: |
| |
| | #2 (permalink) |
| NamePros Regular Join Date: May 2007
Posts: 285
![]() ![]() ![]() | 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
}
}
?> |
| |
| | #3 (permalink) |
| NamePros Member Join Date: Feb 2007 Location: Surabaya - Indonesia
Posts: 27
![]() | ... Hope this help you. PHP Code: |
| |