credit card validation code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
p_sha85
Forum Commoner
Posts: 30
Joined: Sat Mar 21, 2009 1:55 pm

credit card validation code

Post by p_sha85 »

This code keeps giving me an error on line 7 (which might be line 8 in this forum display)... but I don't know what exactly is wrong with it since this is a code straight from the book I'm using. Can someone please make some suggestions? Thanks!

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
function myfunc()
{
<?php 
if (!empty($_GET[\'ccnumber\'])) echo $_GET[\'ccnumber\']; 
if (!isset($_GET[\'ccnumber\']))
echo "<p>Enter your credit card number.</p>";
else {
$Payment = $_GET[\'ccnumber\'];
$ValidPayment = str_replace("-", "", $Payment);
$ValidPayment = str_replace(" ", "", $ValidPayment);
if (!is_numeric($ValidPayment))
echo "<p>You did not enter a valid credit card number!</p>";
else 
echo "<p>Your credit card number is $ValidPayment.</p>";
}
?>
}
<title>Validate Credit Card</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Validate Credit Card</h1><hr />
<form action="ValidateCreditCard.php" method="get" 
enctype="application/x-www-form-urlencoded">
<input type="text" name="ccnumber" size="20" onclick="myfunc()" value="Enter Card Number"/>
<input type="submit" value="Validate Credit Card" />
</form><hr />
</body>
</html>
 
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: credit card validation code

Post by Christopher »

All the PHP code need to be between the tags:

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php 
function myfunc()
{
if (!empty($_GET[\'ccnumber\'])) echo $_GET[\'ccnumber\']; 
if (!isset($_GET[\'ccnumber\']))
echo "<p>Enter your credit card number.</p>";
else {
$Payment = $_GET[\'ccnumber\'];
$ValidPayment = str_replace("-", "", $Payment);
$ValidPayment = str_replace(" ", "", $ValidPayment);
if (!is_numeric($ValidPayment))
echo "<p>You did not enter a valid credit card number!</p>";
else 
echo "<p>Your credit card number is $ValidPayment.</p>";
}
?>
}
<title>Validate Credit Card</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Validate Credit Card</h1><hr />
<form action="ValidateCreditCard.php" method="get" 
enctype="application/x-www-form-urlencoded">
<input type="text" name="ccnumber" size="20" onclick="myfunc()" value="Enter Card Number"/>
<input type="submit" value="Validate Credit Card" />
</form><hr />
</body>
</html>
(#10850)
p_sha85
Forum Commoner
Posts: 30
Joined: Sat Mar 21, 2009 1:55 pm

Re: credit card validation code

Post by p_sha85 »

Okay, I fixed that part but it's still giving the same error tho... this is what I get:

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/a5936353/public_html/ValidateCreditCard.php on line 7

Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /home/a5936353/public_html/ValidateCreditCard.php on line 7
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: credit card validation code

Post by s.dot »

You don't need the \ in $_GET[\'ccnumber'] on line 7.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
p_sha85
Forum Commoner
Posts: 30
Joined: Sat Mar 21, 2009 1:55 pm

Re: credit card validation code

Post by p_sha85 »

Ahhh okay, thank you!
Post Reply