Page 1 of 1

credit card validation code

Posted: Sat Apr 25, 2009 1:05 pm
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>
 

Re: credit card validation code

Posted: Sat Apr 25, 2009 1:22 pm
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>

Re: credit card validation code

Posted: Sat Apr 25, 2009 1:34 pm
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

Re: credit card validation code

Posted: Sat Apr 25, 2009 2:00 pm
by s.dot
You don't need the \ in $_GET[\'ccnumber'] on line 7.

Re: credit card validation code

Posted: Sat Apr 25, 2009 2:07 pm
by p_sha85
Ahhh okay, thank you!