473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Allowing two "if" statements

Lazandra
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
3 1614
ak1dnar
1,584 Expert 1GB
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
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
1,584 Expert 1GB
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

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

Similar topics

40
by: Steve Juranich | last post by:
I know that this topic has the potential for blowing up in my face, but I can't help asking. I've been using Python since 1.5.1, so I'm not what you'd call a "n00b". I dutifully evangelize on the...
35
by: David Cleaver | last post by:
Hello all, I was wondering if there were some sort of limitations on the "if" statement? I'm writing a program which needs to check a bunch of conditions all at the same time (basically). And...
12
by: junky_fellow | last post by:
Which is better using a switch statement or the if-then equivalent of switch ?
3
by: sapnsapn | last post by:
Hi folks, I am looking at an application written in C some 10+ years ago. There is a lot of such if statements: if (my_number) {....} else {...} Here, my_number is an unsigned int. What exactly...
3
by: Mark Sullivan | last post by:
When I trace through a csharp program I came to a situation where a certain values has an "undefined value" as shown in the debugger DbgClr. I want to check this but the following statements did...
12
by: John | last post by:
I can't get my head around this! I have the following code: <% .... Code for connection to the database ... .... Code for retrieving recordset ... If Not rs.EOF Then ... Do something...
2
by: marsarden | last post by:
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
0
by: Germaris | last post by:
Hi there! On my form I have two ComboBoxes. The first displays a list of countries. The second one, if the country selected in the first ask for, displays a list of states, provinces or...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.