-1

I am trying to create a simple payment.php file that handles form posting from a buyaticket.html file.

I need to write an if statement, so that the website will display this:`

<h1>Thanks, customer!</h1>
<p>Your information has been recorded.</p>


<dl>
    <dt>Name:</dt>
    <dd><?php print $_POST['name']; ?></dd>
    <dt>Seat:</dt>
    <dd><?php print $_POST['seats']; ?></dd>
    <dt>Credit Card Type:</dt>
    <dd><?php print $_POST['cardtype']; ?></dd>
    <dt>Credit Card Number:</dt>
    <dd><?php print $_POST['creditcardnumber']; ?></dd>
</dl>`

if all of the names (name, seats, cardtype, creditcardnumber) are filled out. In addition, the creditcardnumber must be an int.

if they are not filled out (i.e. empty or null), then i need to display a simple html tag stating that you haven't filled out the form correctly.

Can anyone help me with my problem? I need to know how to write an IF statement that will show an error message if the inputs (name, credit card number, etc) are left blank, and if they are filled out i will show the above mentioned code showing all of the users input information.

this is what i was playing with (not my actual code. just thoughts):

if empty('name') or empty('cardtype') or empty('seats') or empty('creditcardnumber') 
  <h1>You have filled out the form incorrectly</h1>
else
  <dl>
  </dl?

but i don't know how to check for creditcardnumber being an integer, as well.

Thanks in advance for any help!

bizzehdee
  • 20,289
  • 11
  • 46
  • 76
Jack
  • 17
  • 2

5 Answers5

1

Never check an creditcard number with is_numeric but with the checksum and pattern.

Here is a great answer: What is the best way to validate a credit card in PHP?

Community
  • 1
  • 1
S.Visser
  • 4,645
  • 1
  • 22
  • 43
0

Check is_numeric() That's the function you need. http://www.php.net/manual/en/function.is-numeric.php

frisco
  • 1,897
  • 2
  • 21
  • 29
0

You can check weather creditcard number is integer with function

is_numeric

Jakuje
  • 24,773
  • 12
  • 69
  • 75
0
if (isset($_POST['name']) && isset($_POST['name']) && isset($_POST['cardtype']) && isset($_POST['cardtype']) && isset($_POST['creditcardnumber']) && is_int($_POST['creditcardnumber']))
{echo('good job');}
else {echo('bad job');}
user1032531
  • 24,767
  • 68
  • 217
  • 387
  • thank you all for your help. does this statement sound like it would work: `if (!empty($_POST['name']) && !empty($_POST['seats']) && !empty($_POST['creditcardnumber']) && !empty($_POST['cardtype']) && (is_int($_POST['creditcardnumber'])==True){` – Jack Apr 17 '13 at 15:54
0

You may simply write

<?php

if($_POST['name'] && $_POST['seats'] && $_POST['cardtype'] && $_POST['creditcardnumber']){

//your action for displaying input

}else{
?>
<h1>You have filled out the form incorrectly</h1>
<?php
}

?>

Although I suggest to put include a name to your submit button to verify if the form was really submitted. Lets say your submit button's name is 'submit'.

    <?php

    if($_POST['submit']){

    //your validation code
     if($_POST['name'] && $_POST['seats'] && $_POST['cardtype'] && $_POST['creditcardnumber']){
    ...
    }else{
    //prompt user for incomplete fields
    }

    } 
?>
Jereme
  • 621
  • 6
  • 14