i have 4 input box of credit card number and 2 boxes of credit card expire date month and year and one for the card holder name i have some code but is it ok or i have to do some thing else

<?php

$connection = mysql_connect("localhost","root","password") or die("error connect");
mysql_select_db("online_bus_project");

if(isset($_POST['submit']))
{
 $first_name = $_POST["fname"];

$len = strlen($first_name);

if ($len >0)
{
$card_number = $_POST["card_number1","card_number2","card_number3","card_number4"];
$expiry_date = $_POST["card_exp_mm","card_exp_yy"];
   
}



	$query = "INSERT INTO payment (name, number, expire) VALUES('$first_name', '$card_number', '$expiry_date')";
	mysql_query($query, $connection) or die(mysql_error());
}
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="obrs.css" rel="stylesheet" type="text/css" />
<!--[if IE 5]>
<style type="text/css"> 
/* place css box model fixes for IE 5* in this conditional comment */
.twoColFixRtHdr #sidebar1 { width: 220px; }
</style>
<![endif]--><!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.twoColFixRtHdr #sidebar1 { padding-top: 30px; }
.twoColFixRtHdr #mainContent { zoom: 1; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<style type="text/css">
<!--
.style1 {
	color: #FFFF00;
	font-weight: bold;
}
.style2 {
	color: #FFFF66;
	font-weight: bold;
}
#payment_box {
	height: 40px;
	width: 150px;
	margin-top: 100px;
}
#payment_form {
	height: 150px;
	width: 400px;
	margin-top: 40px;
}
.style3 {
	font-size: 16px;
	font-weight: bold;
	color: #333333;
}
-->
</style>
</head>

<body class="twoColFixRtHdr">

<div id="container">
  <div id="header">
    <!-- end #header -->
    <img src="images/header" alt="OBTRS: Header" /></div>
  <div id="sidebar1">
    <!-- end #sidebar1 -->
    <img src="images/sidebar_slideshow" alt="" />
    <div id="blogarea">
      <p class="style2">Casual Dining Restaurants</p>
      <p><br />
        Our family-style restaurants are the favorite of thousands of tourists and professional drivers alike. Our clean and friendly surroundings encourage people to stop and enjoy a wholesome meal with us when they travel. Our customers recognize our strong teamwork ethic as we provide them quality service.</p>
      <p><br />
          <span class="style1">Convenience Stores</span></p>
      <p><br />
        Our cashiers take pride in having the items on the shelf ready for our travelers when they stop. We know many are in a hurry and we need to be &quot;fast&quot; to meet their busy schedules. Some of our returning customers enjoy fresh coffee and we have it ready for them. The joint effort of our managers and associates creates a strong &quot;team spirit&quot; that provides the customers what they are looking for as they travel.</p>
    </div>
  </div>
  <div id="mainContent">
    <div id="nav">
      <script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','760','height','30','src','images/nav_bar2','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','images/nav_bar2' ); //end AC code
    </script>
      <noscript>
      <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="760" height="30">
        <param name="movie" value="images/nav_bar2.swf" />
        <param name="quality" value="high" />
        <embed src="images/nav_bar2.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="760" height="30"></embed>
      </object>
      </noscript>
    </div>
    <CENTER>
    <form name="payment" action="" method="post">

      <div class="style3" id="payment_box"> Make Payment<br />
        Card Details </div>
    <center><div id="payment_form">
      <div align="left">
        <p class="style3">Card Holder's Name: <input type="text" name="chname" /><br /><br />
          Card Number:             
          <INPUT name=card_number1 size=4 maxlength=4>&nbsp;<INPUT name=card_number2 size=4 maxlength=4>&nbsp;<INPUT name=card_number3 size=4 maxlength=4>&nbsp;<INPUT name=card_number4 size=4 maxlength=4>&nbsp;<br />
          <br />
        Card Expiry Date:       <INPUT name=card_exp_mm size=2 maxlength=2> / <INPUT name=card_exp_yy
            size=4 maxlength=4><br /><br /><center><input type="submit" value="Submit"></div>
    </div>
    </form>
    </center>
    <div id="features"></div>
    <!-- end #mainContent -->
  </div>
  <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats -->
  <br class="clearfloat" />
  <div id="footer">
    <p><a href="aboutus.html">About us</a> |<a href="feedback.html"> Feedback</a> |<a href="faqs.html"> FAQs</a> | <a href="terms.html">Terms &amp; Conditions</a> | <a href="contactus.html">Contact us</a></p>
    <p> 2009 Copyright - Shah Abdul Latif University Khairpur</p>
    <!-- end #footer -->
  </div>
  <!-- end #container -->
</div>

</body>
</html>

Dani AI

Generated

Quick diagnosis and practical fixes (why the form sometimes "worked" and often did not)

The main issues seen in the thread were not PHP magic — they were simple form/field mismatches and an insecure workflow. was right to suggest joining the four card fields, and and were correct to point at form-post logic, but three concrete problems kept the insert from running: the form’s input names did not match the keys you read in PHP (your HTML uses name="chname" while PHP reads $_POST['fname']), the submit button had no name yet the script checked a $_POST key for it, and the form action pointed to a static file (index.html) instead of the PHP processor. Posting to a file without the processing code (or to an .html) will never run your PHP.

Minimal, reliable fixes and safe handling

  • Make input name attributes match what the PHP expects, or change the PHP to match the HTML.
  • Detect form submission by checking the request method (POST) instead of relying on a submit field name.
  • Collect and sanitize the four card parts, then join them. Example of a safe collection + last‑4 extraction:
$parts = [
  filter_input(INPUT_POST, 'card_number1', FILTER_SANITIZE_NUMBER_INT),
  filter_input(INPUT_POST, 'card_number2', FILTER_SANITIZE_NUMBER_INT),
  filter_input(INPUT_POST, 'card_number3', FILTER_SANITIZE_NUMBER_INT),
  filter_input(INPUT_POST, 'card_number4', FILTER_SANITIZE_NUMBER_INT),
];
$pan = implode('', $parts);
$last4 = substr($pan, -4);

Use parameterized queries (PDO or mysqli) and never interpolate user data into SQL. Example insert that stores only the last 4 digits:

$pdo = new PDO(..., [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
$stmt = $pdo->prepare('INSERT INTO payment (cardholder, pan_last4, expire) VALUES (:name, :last4, :expire)');
$stmt->execute([':name'=>$holder, ':last4'=>$last4, ':expire'=>$expiry]);

Security, compliance and debugging tips
Do not store full PANs in plain text. For any real payments use a PCI-compliant gateway/tokenization provider; if you must store card info follow PCI DSS (encryption, limited access, logging). Use TLS for the form, enable PHP error reporting during debugging, log/inspect $_POST (or var_dump) to confirm values, and handle DB errors (exceptions or mysql_error()) so failures are visible. For reference on best practices for prepared statements and safe output, see the PHP docs on PDO prepared statements (https://www.php.net/manual/en/pdo.prepared-statements.php) and on escaping output (https://www.php.net/manual/en/function.htmlspecialchars.php). For PCI rules consult the PCI Security Standards Council (https://www.pcisecuritystandards.org/).

Recommended Answers

All 12 Replies

$card_number = $_POST["card_number1"] . $_POST["card_number2"] . $_POST["card_number3"] . $_POST["card_number4"];
$expiry_date = $_POST["card_exp_mm"] . $_POST["card_exp_yy"];

thanx for the help no errors but data isn't sending to the table why?

even i have put in the action="index.html" so after sending this data it will return to the index

thanx for the help no errors but data isn't sending to the table why?

even i have put in the action="index.html" so after sending this data it will return to the index

$result = mysql_query(""INSERT INTO payment (name, number, expire) VALUES('$first_name', '$card_number', '$expiry_date')");

again no errors and data not sent to the table payment????

<?php

$connection = mysql_connect("localhost","root","password") or die("error connect");
mysql_select_db("online_bus_project");

if(isset($_POST['submit']))
{
 $first_name = $_POST["fname"];

$len = strlen($first_name);

if ($len >0)
{

$card_number = $_POST["card_number1"] . $_POST["card_number2"] . $_POST["card_number3"] . $_POST["card_number4"];

$expiry_date = $_POST["card_exp_mm"] . $_POST["card_exp_yy"]; 
}

$result = mysql_query("INSERT INTO payment (name, number, expire) VALUES('$first_name', '$card_number', '$expiry_date')"); 

	
}
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="obrs.css" rel="stylesheet" type="text/css" />
<!--[if IE 5]>
<style type="text/css"> 
/* place css box model fixes for IE 5* in this conditional comment */
.twoColFixRtHdr #sidebar1 { width: 220px; }
</style>
<![endif]--><!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.twoColFixRtHdr #sidebar1 { padding-top: 30px; }
.twoColFixRtHdr #mainContent { zoom: 1; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<style type="text/css">
<!--
.style1 {
	color: #FFFF00;
	font-weight: bold;
}
.style2 {
	color: #FFFF66;
	font-weight: bold;
}
#payment_box {
	height: 40px;
	width: 150px;
	margin-top: 100px;
}
#payment_form {
	height: 150px;
	width: 400px;
	margin-top: 40px;
}
.style3 {
	font-size: 16px;
	font-weight: bold;
	color: #333333;
}
-->
</style>
</head>

<body class="twoColFixRtHdr">

<div id="container">
  <div id="header">
    <!-- end #header -->
    <img src="images/header" alt="OBTRS: Header" /></div>
  <div id="sidebar1">
    <!-- end #sidebar1 -->
    <img src="images/sidebar_slideshow" alt="" />
    <div id="blogarea">
      <p class="style2">Casual Dining Restaurants</p>
      <p><br />
        Our family-style restaurants are the favorite of thousands of tourists and professional drivers alike. Our clean and friendly surroundings encourage people to stop and enjoy a wholesome meal with us when they travel. Our customers recognize our strong teamwork ethic as we provide them quality service.</p>
      <p><br />
          <span class="style1">Convenience Stores</span></p>
      <p><br />
        Our cashiers take pride in having the items on the shelf ready for our travelers when they stop. We know many are in a hurry and we need to be &quot;fast&quot; to meet their busy schedules. Some of our returning customers enjoy fresh coffee and we have it ready for them. The joint effort of our managers and associates creates a strong &quot;team spirit&quot; that provides the customers what they are looking for as they travel.</p>
    </div>
  </div>
  <div id="mainContent">
    <div id="nav">
      <script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','760','height','30','src','images/nav_bar2','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','images/nav_bar2' ); //end AC code
    </script>
      <noscript>
      <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="760" height="30">
        <param name="movie" value="images/nav_bar2.swf" />
        <param name="quality" value="high" />
        <embed src="images/nav_bar2.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="760" height="30"></embed>
      </object>
      </noscript>
    </div>
    <CENTER>
    <form name="payment" action="index.html" method="post">

      <div class="style3" id="payment_box"> Make Payment<br />
        Card Details </div>
    <center><div id="payment_form">
      <div align="left">
        <p class="style3">Card Holder's Name: <input type="text" name="chname" /><br /><br />
          Card Number:             
          <INPUT name=card_number1 size=4 maxlength=4>&nbsp;<INPUT name=card_number2 size=4 maxlength=4>&nbsp;<INPUT name=card_number3 size=4 maxlength=4>&nbsp;<INPUT name=card_number4 size=4 maxlength=4>&nbsp;<br />
          <br />
        Card Expiry Date:       <INPUT name=card_exp_mm size=2 maxlength=2> / <INPUT name=card_exp_yy
            size=4 maxlength=4><br /><br /><center><input type="submit" value="Submit"></div>
    </div>
    </form>
    </center>
    <div id="features"></div>
    <!-- end #mainContent -->
  </div>
  <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats -->
  <br class="clearfloat" />
  <div id="footer">
    <p><a href="aboutus.html">About us</a> |<a href="feedback.html"> Feedback</a> |<a href="faqs.html"> FAQs</a> | <a href="terms.html">Terms &amp; Conditions</a> | <a href="contactus.html">Contact us</a></p>
    <p> 2009 Copyright - Shah Abdul Latif University Khairpur</p>
    <!-- end #footer -->
  </div>
  <!-- end #container -->
</div>

</body>
</html>

its working now with some changes but still i havent understand this thing:-


If im putting this code on action="<?php echo $_SERVER; ?>" then its working sending data to mysql table

if im putting some link to this like action="index.php" its not working why????

any one have answer to this

why do you need

if ($len >0)
{ 

}

there are better ways of checking if it is empty. make sure that you are posting the data to itself though. you can just use the file name

why do you need

if ($len >0)
{ 

}

there are better ways of checking if it is empty. make sure that you are posting the data to itself though. you can just use the file name

ok then can u tell me any ideas?

if legth is 0 on input field it gives error?


why its working on it self and not in the other page

ok.

if(empty($_POST['fname'])){
   echo "Empty first name!";
}
//or you can also do it this way
if($_POST['fname']==""){
 echo "Empty first name!";
}

as for what you are trying to do. is that php code in the other page? i am lost when you say

why its working on it self and not in the other page

as far as i know this is one page and if you post the data on itself then it will process it. but if you post the data on another page you just have to make sure that, that code is in that page

ok.

if(empty($_POST['fname'])){
   echo "Empty first name!";
}
//or you can also do it this way
if($_POST['fname']==""){
 echo "Empty first name!";
}

as for what you are trying to do. is that php code in the other page? i am lost when you say


as far as i know this is one page and if you post the data on itself then it will process it. but if you post the data on another page you just have to make sure that, that code is in that page

thanx for the help i understand now.
but what should i do i want that if data send goto other page for further process i mean for more information i can give a hyper link below it will not look good.

i have seen many form if some one press the button it takes to the other page also it sends tha data?

ok.

if(empty($_POST['fname'])){
   echo "Empty first name!";
}
//or you can also do it this way
if($_POST['fname']==""){
 echo "Empty first name!";
}

as for what you are trying to do. is that php code in the other page? i am lost when you say


as far as i know this is one page and if you post the data on itself then it will process it. but if you post the data on another page you just have to make sure that, that code is in that page

thanx for the help i understand now.
but what should i do i want that if data send goto other page for further process i mean for more information i can give a hyper link below it will not look good.

i have seen many form if some one press the button it takes to the other page also it sends tha data?

i have seen many form if some one press the button it takes to the other page also it sends tha data?

well Yeah, php form processing is in the target page not the form page
and validation failure is something like
if !$post['variable'] {header ("location: $_SERVER['http_referer']"); }[code=php]if !$post {header ("location: $_SERVER"); }

thanx for the help guys its solved appreciate thanx to all posters.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.