-2

I am attempting to validate a credit card number input to be at least 16 numbers. My code doesn't seem to work. I don't feel too confident about my syntax. Any help?... thanks.

<form name="ccard" action="validate.php" method=post>
CC Type
<select name="cc_type">
<option value="mc">Master Card</option>
<option value="visa">Visa</option>
</select><br>
Creditcard number:
<input type=number name="ccard_num" value="num"><br>
Exp Year:
<input><br>
Exp Month:
<input>
</form>

php code

<?php
$cc_length = $_POST['ccard_num'];

if (strlen( $cc_length == 15) {
echo "Valid";
}
elseif (strlen($cc_length != 15) {
echo "Invalid entry";
}
?>
D0uble0
  • 175
  • 1
  • 2
  • 12

2 Answers2

1

strlen returns the length of a string. You need to compare the return value of this function. Right now you comparen the string value to a number and then pass this boolean value to the strlenfunction. Change your code to:

<?php
$cc_length = $_POST['ccard_num'];

    if ( strlen($cc_length) == 15 ) {
    echo "Valid";
}
    elseif ( strlen($cc_length) != 15 ) {
    echo "Invalid entry";
}
?>
dbarthel
  • 130
  • 1
  • 11
-1

Your IF condition, no closing parenthesis, its very obvious.

user1149244
  • 711
  • 4
  • 10
  • 27