fourthe Posted March 5, 2009 Share Posted March 5, 2009 I know this isn't secure, i'm not using this for real. I've created a form with 3 buttons and a text field. I would like it when a user clicks the amex button and when the number of numbers equal to 15 to confirm the number but if any of the other buttons are clicked and the numbers are equal to 16 then tell the card number. For some reason i cant get it to work, I think maybe my values are wrong? idk. If someone could help that would be great thanks. <?php $amex = $_REQUEST["amex"]; $card = $_REQUEST["card"]); $cardlen = strlen(trim($card)); $visa = $_REQUEST["visa"]; $master = $_REQUEST["master"]; if ($amex == 1 && $cardlen == 15) { echo "American Express Card Number:" . $card; } elseif (($visa == 1 || $master == 1) && $cardlen == 16) { echo "Visa or Master Card Number:" . $card; } else { echo "Please enter the correct card number"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148089-php-if-statement-help/ Share on other sites More sharing options...
rhodesa Posted March 5, 2009 Share Posted March 5, 2009 nothing jumps out at me...can you post the form or the output of print_r($_REQUEST) ? Quote Link to comment https://forums.phpfreaks.com/topic/148089-php-if-statement-help/#findComment-777324 Share on other sites More sharing options...
fourthe Posted March 5, 2009 Author Share Posted March 5, 2009 ok i will post both the form and then the full php code. <html> <body> <p>Payment</p> <form action="payment.php"> Cardholder's Name: <input type="text" name="name" /> <br> Credit Card Number: <input type="text" name="card" /> <br> Expiration Date: <input type="text" name="date" /> <br> Security Code: <input type="text" name="code" /> <br> <input type="radio" name="button" value="visa" /> Visa <br> <input type="radio" name="button" value="master" /> MasterCard <br> <input type="radio" name="button" value="amex" /> American Express <br> <input type="submit" value="Submit" /> </form> </body> </html> ----------------------------------- <HTML> <body> <?php if (strlen($_REQUEST["name"]) > 0) { echo "Name:" . $_REQUEST["name"]; } else echo "You must insert your name"; ?> <br> <?php if (strlen($_REQUEST["date"]) > 0) { echo "Expiration Date:" . $_REQUEST["date"]; } else echo "You must insert your expiration date"; ?> <br> <?php if (strlen($_REQUEST["code"]) > 0) { echo "Security Code:" . $_REQUEST["code"]; } else echo "You must insert your security code"; ?> <br> <?php $amex = $_REQUEST["amex"]; $card = $_REQUEST["card"]); $cardlen = strlen(trim($card)); $visa = $_REQUEST["visa"]; $master = $_REQUEST["master"]; if ($amex == 1 && $cardlen == 15) { echo "American Express Card Number:" . $card; } elseif (($visa == 1 || $master == 1) && $cardlen == 16) { echo "Visa or Master Card Number:" . $card; } else { echo "Please enter the correct card number"; } ?> </body> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/148089-php-if-statement-help/#findComment-777333 Share on other sites More sharing options...
rhodesa Posted March 5, 2009 Share Posted March 5, 2009 ok, next time, on your PHP page, do a print_r($_REQUEST) if it's not doing what you expect. you will see that there is no $_REQUEST['amex'] or $_REQUEST['visa'], etc. you use a radio button with the name 'button'. so there will be a $_REQUEST['button'] that is either equal to amex, visa, or master Quote Link to comment https://forums.phpfreaks.com/topic/148089-php-if-statement-help/#findComment-777348 Share on other sites More sharing options...
fourthe Posted March 5, 2009 Author Share Posted March 5, 2009 So how would I make the If statement with the buttons? Quote Link to comment https://forums.phpfreaks.com/topic/148089-php-if-statement-help/#findComment-777449 Share on other sites More sharing options...
fourthe Posted March 5, 2009 Author Share Posted March 5, 2009 ok i think im on the right track but still not working: <?php //$amex = $_REQUEST["amex"]; $card = $_REQUEST["card"]); $cardlen = strlen(trim($card)); //$visa = $_REQUEST["visa"]; //$master = $_REQUEST["master"]; if ($card == amex && $cardlen == 15) { echo "American Express Card Number:" . $card; } elseif (($card == visa || $card == master) && $cardlen == 16) { echo "Visa or Master Card Number:" . $card; } else { echo "Please enter the correct card number"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148089-php-if-statement-help/#findComment-777468 Share on other sites More sharing options...
kickstart Posted March 5, 2009 Share Posted March 5, 2009 Hi You are missing quotes around the names of the various cards. Eg should be $card == 'amex' All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/148089-php-if-statement-help/#findComment-777474 Share on other sites More sharing options...
fourthe Posted March 5, 2009 Author Share Posted March 5, 2009 ok i fixed the quotes and fixed the variable for button. but i think im missing something else cause its not working. <?php $button = $_REQUEST["button"]); $cardlen = strlen(trim($card)); if ($button == 'amex' && $cardlen == 15) { echo "American Express Card Number:" . $card; } elseif (($button == 'visa' || $button == 'master') && $cardlen == 16) { echo "Visa or Master Card Number:" . $card; } else { echo "Please enter the correct card number"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148089-php-if-statement-help/#findComment-777477 Share on other sites More sharing options...
fourthe Posted March 5, 2009 Author Share Posted March 5, 2009 i also added just added $card = $_REQUEST["card"]); Quote Link to comment https://forums.phpfreaks.com/topic/148089-php-if-statement-help/#findComment-777479 Share on other sites More sharing options...
rhodesa Posted March 5, 2009 Share Posted March 5, 2009 the code worked for me. this is what i'm testing with...i altered the FORM tag so that i posts to the same page just for testing purposes: <?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ $card = $_REQUEST["card"]; $button = $_REQUEST["button"]; $cardlen = strlen(trim($card)); if ($button == 'amex' && $cardlen == 15) { echo "American Express Card Number:" . $card; } elseif (($button == 'visa' || $button == 'master') && $cardlen == 16) { echo "Visa or Master Card Number:" . $card; } else { echo "Please enter the correct card number"; } } ?> <html> <body> <p>Payment</p> <form method="post" action=""> Cardholder's Name: <input type="text" name="name" /> <br> Credit Card Number: <input type="text" name="card" /> <br> Expiration Date: <input type="text" name="date" /> <br> Security Code: <input type="text" name="code" /> <br> <input type="radio" name="button" value="visa" /> Visa <br> <input type="radio" name="button" value="master" /> MasterCard <br> <input type="radio" name="button" value="amex" /> American Express <br> <input type="submit" value="Submit" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/148089-php-if-statement-help/#findComment-777482 Share on other sites More sharing options...
fourthe Posted March 5, 2009 Author Share Posted March 5, 2009 Did you change anything? Because it works. LOL thank you Quote Link to comment https://forums.phpfreaks.com/topic/148089-php-if-statement-help/#findComment-777489 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.