![]() |
How can I pick up two variables at the same time.
Hi Guys...
I have almost finidhed my cart, but I have a problem that I don'yt know how to code. From the form: PHP Code:
PHP Code:
But the problem is that ALL the options are selected as YES. I need to somehow select: if(isset($_POST['cash'])) AND value = YES, in order to just select one. I know that one solution would be to change from radio button to select box, but some idiot would select ALL options. Can anybody advice me how to solve my problem ??? Thanks, |
With radio buttons they cannot select ALL of them if the "name" is the same.
They can do that with checkboxes, but not radio buttons. See this test script. You have already given each radio button a value in your form. Now you just need to see which one they picked ... PHP Code:
EDIT: fixed typo . |
Hi mlseim..
Very many thanks for your help - ONCE AGAIN. You actually made a slight mistake in your code. The lst bracket was ) not } I soon managed to sort this out and then recode the rest of the script to work as I need it to. Don't know whether you remember, but back around June this year you helped me with this project. You have no idea how much I appreciated your help then, as well as now. I will NEVER FORGET !!! Thank you... |
Hi
I wonder if I can ask your advice. What is the difference between: PHP Code:
PHP Code:
|
The best way to explain it ...
Upload this script, call it "test.php" and try it. PHP Code:
Important if you expect the integer zero (0) to be entered. PHP will see this as a 'false' in the IF statement. You can combine them to see if they entered nothing. If ISSET and then if it's not empty. If nothing is entered, you may want to do something about it ... or maybe you don't care. Depends on your specifications. There is also the EMPTY command. I know ... it is sort of confusing. Thinking about it now ... I probably mis-use it many times. Test your forms for all possible user entries. Fou Lu probaby can explain it better than anyone here. . |
Yep, isset is simply to check the existence of a variable, and that it is not null. It otherwise does not care about the value of the variable. Input from forms cannot be null, only empty strings.
PHP Code:
PHP Code:
With the example you have here, you can use a ternary operation for it: $delivery = isset($_POST['delivery']) ? $_POST['delivery'] : 'none';. Just like any if, you can group as many conditions as you want into it.Empty checks that a variable exists and is an empty value (false equivalent). Although faith in my memory is kinda diminishing a bit, I'm quite sure that empty() used to trigger notice when the variable does not exist. Currently it does not. Empty can be used in place of isset if you demand that a provided value cannot be a false equivalent. This is unlike isset as isset considers "" or 0 to be valid. Empty does not. Personally, I use empty during validation phases, but not during initial verification. Don't use empty on something like a quantity, otherwise it will never pass the 0 check (for which you likely need to remove it from a cart for example instead of ignoring the input completely). So to sum it up (which mlseim did): PHP Code:
PHP Code:
|
Very many thanks to both of you.
|
| All times are GMT +1. The time now is 09:24 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.