Irin, Quite a number of issues here, actually. We'll start with your question and work from there. Using the checkbox <input type="checkbox" name="Cheque" value="Cheque"> as an example, the code you would use to check if it was set is:
if($_GET['Cheque'] == 'Cheque') { // The Cheque checkbox was checked. } else { // The Cheque checkbox was NOT checked. } I cannot see why you would need an if...else if...else structure here unless you only wanted to see if the Cash, Nets, OR Cheque checkbox was selected. In that case I would use radio buttons instead of checkboxes and give them all the same name, e.g. <input type="radio" name="paymentType" value="Cash"> <input type="radio" name="paymentType" value="Nets"> <input type="radio" name="paymentType" value="Cheque"> Then do something like: if($_GET['paymentType'] == 'Cash') { // The Cash checkbox was checked. } else if($_GET['paymentType'] == 'Nets') { // The Nets checkbox was NOT checked. } else { // This must be the Cheque radio button. } Now a couple of caveats in your script: You are using the GET method to send form data, which is fine. Just be careful when sending large forms, as there is a limit on the amount of data you can send using GET. I recommend using the POST method instead because you can set the MAX_POST_SIZE in your php.ini file. Next: Cash: <?php echo "$$_GET[cheque]";?><BR> This code fragment and others like it in your script are problematic. $$_GET['cheque'] is actually saying "Give me the value stored in $_GET['cheque'], use that as a variable name, and retrieve the value stored in that new variable." In simplified code this would look like: <?php $_GET['cheque'] = 'foo'; $foo = 'bar'; echo $_GET['cheque']; // Returns 'foo'; echo $$_GET['cheque']; // Returns 'bar'; ?> If you don't want the extra dollar sign to be interpreted then do something like this: Cash: <?php echo "\$$_GET[cheque]";?><BR> Next, your array index name MUST be surrounded by either single or double quotes unless it is a number or a constant. If you don't, PHP assumes you are actually asking for the value stored in a constant named 'cheque'. Thus, your code becomes this: Cash: <?php echo "\$$_GET['cheque']";?><BR> Lastly, PHP really likes array variables to be enclosed in curly braces when they are used within a string. This means one final change: Cash: <?php echo "\$${_GET['cheque']}";?><BR> I hope that answered your question! -Rob -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 01, 2003 11:04 PM To: [EMAIL PROTECTED] Subject: if..else condition for checkbox Hi all, May I just ask how do I do a "if..elseif..else" condition to check if a "checkbox" have been checked. For some reference, I have attached my HTML code and PHP code below: HTML: <html> <head> <title>Payment Mode</title> <style type="text/css"> @import url(receipt.css); </style> </head> <body> <form action="checkbox.php" method="get"> <br><br><br> <div id="pagecontent1"> <div class="sectionheading"> Payment Mode:<br> </div> <div class="lighter"> <input type="checkbox" name="Cash" value="Cash" >Cash<br> </div> <div class="darker"> <input type="checkbox" name="Nets" value="Nets">Nets<br> </div> <div class="lighter"> <input type="checkbox" name="Cheque" value="Cheque">Cheque<br></div><br> <div class="sectionheading"> *For Cheque plus Cash payment only: </div> <div class="lighter"> Cheque: $ <input name="cheque" type="text" size="6" maxlength="6"><br> </div> <div class="darker"> Cash: $ <input name="cash" type="text" size="6" maxlength="6"><br></div><br> <input type="submit" name="submit" value="submit" align="center"> </div> </form> </form> </body></html> PHP Code: <HTML> <HEAD> <title>Payment Mode</title> <style type="text/css"> @import url(receipt.css); </style> </HEAD> <BODY> <br><br> <div id="pagecontent1"> <div class="sectionheading"> <br> <tr> <td valign="top" class="darker" width="200"> <?php } ?> <?php echo "Payment Mode:Cash Plus Cheque"; ?> <br> </div> </td> Cash: <?php echo "$$_GET[cheque]";?><BR> Cheque:<?php echo "$$_GET[cash]";?><BR> <br> <?php $total = $_GET[cheque] + $_GET[cash]; $total=number_format($total, 2, ".", " "); echo "<BR>Total payable: $$total<BR><BR>"; ?> </div> </BODY> </HTML> Regards, Irin. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php