By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,505 Members | 1,034 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,505 IT Pros & Developers. It's quick & easy.

Allowing two "if" statements

Lazandra
P: 25
I have a form, and if credit card details have been entered i want it to save in the field completed a "c". However if it doesnt have the credit card details i want it to save to the field completed a "n". I have done code for it. But can you have two "if" statements in one query?

Heres my code:

[PHP]if ($submit == "Save" || $payment_cc != "")
{
$saved = mysql("db69117798","insert into payment values (0, '$infoid', '$product_dogmobile', '$product_dogwalker', '$product_harness', '$product_harness_area', '$product_new', '$postage', '$total', '$payment_name', '$payment_cc', '$payment_valid_from', '$payment_expiry', '$payment_issue', '$payment_security_number', '$payment_type', NOW()), 'c'");

if ($saved)
{
echo "Thank you for your order. Your Order Number is - <b>$infoid</b>";
exit;
}
else
{
echo mysql_error() ;
}

}

if ($submit == "Save" || $payment_cc == "")
{
$saved = mysql("db69117798","insert into payment values (0, '$infoid', '$product_dogmobile', '$product_dogwalker', '$product_harness', '$product_harness_area', '$product_new', '$postage', '$total', '$payment_name', '$payment_cc', '$payment_valid_from', '$payment_expiry', '$payment_issue', '$payment_security_number', '$payment_type', NOW()), 'n'");

if ($saved)
{
echo "Thank you for your order. Your Order Number is - <b>$infoid</b>";
exit;
}
else
{
echo mysql_error() ;
}

} [/PHP]

Any help would be greatly appreciated.

Laz
xxxx
Oct 8 '07 #1
Share this Question
Share on Google+
3 Replies


ak1dnar
Expert 100+
P: 1,584
Laz, of course you can use any number of "if conditions" in a single page.
But This way is so easier than yours;

input_form.php

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <form action="server.php" method="post">
  4. <input name="cc" type="text" />
  5. <input name="save" type="submit" />
  6. </form>
  7. </body>
  8. </html>
server.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_POST['save'])){
  3.     if(isset($_POST['cc']) && ($_POST['cc']!="")){
  4.     $CC = 'c';
  5.     }else{
  6.     $CC = 'n';
  7.     }
  8.     echo $CC;
  9.  
  10.     $mySQLQuery = "insert into table(COL1,COL2,COL3)values('col1','clo2','$CC')";
  11.     echo $mySQLQuery;
  12.     /*
  13.     Execute the Query Here using mysql_query($mySQLQuery)
  14.     */
  15. }
  16. ?>
  17.  
Oct 8 '07 #2

Lazandra
P: 25
Thats brilliant! Thanks ajaxrand.

So "isset" can be used if you have assigned a variable and want to check it?

This is so much easier than mine.

thanks so much!
xxxx
Oct 10 '07 #3

ak1dnar
Expert 100+
P: 1,584
If the variable exist isset() will set to true, false other wise. and it will return FALSE for variables that has been set to NULL
Oct 10 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.