I am creating a page where user enters the details through a registration form for a bank database. If the input values exits in the database then it is redirected to the next page. The problem associated with the code below is that when the user enters the details it redirects to the same registration page. The page is accessed through a separate file where the connection with the database is already established. No problem with the connection. I have created a file 'index.php' which invokes the registration page and the php code shown below. another file core.php is referred to the index.php which contains the session_start(). The code works well when i am limiting the form to only two fields i.e cust_name & card_no. Please reply. Thanks in advance. Here is my code:
<?php
//require 'core.php';
//echo $current_file;
if (isset($_POST['cust_name']) && isset($_POST['card_no']) && isset($_POST['cvv']) && ($_POST['exp_month']) && ($_POST['exp_year'])) //error possibly in this part
{
$cust_name = $_POST['cust_name'];
$card_no = $_POST['card_no'];
$cvv = $_POST['cvv'];
$exp_month = $_POST['exp_month'];
$exp_year = $_POST['exp_year'];
if(!empty($cust_name) && !empty($card_no) && !empty($cvv) && !empty($exp_month) && !empty($exp_year)) //error possible in this part
{
$query = "SELECT id FROM bank WHERE cust_name='$cust_name', card_no='$card_no',cvv='$cvv', exp_month='$exp_month',exp_year='$exp_year' ";
if($query_run = mysql_query($query))
{
$query_num_rows = mysql_num_rows($query_run);
if($query_num_rows==0)
{
echo 'Invalid Card details';
}
else if($query_num_rows==1)
{
//echo 'OK!!';
$user_id = mysql_result($query_run,0,'id');
$_SESSION['user_id']=$user_id; //starts the session
header('Location:login2.php');/*redirects if the details are present in database*/
}
}
}
else
{
echo 'PLEASE ENTER DETAILS';
}
}
?>
<form action ="<?php echo $current_file; ?>" method="POST">//registration form
Card Name:<input type = "text" name = "cust_name"><br/>
Card No:<input type = "text" name = "card_no"><br/>
CVV:<input type = "text" name = "cvv"><br/>
Expiry Month & Year<select name="exp_month"><br/>
<option selected value="janauary">January</option>
<option value="february">February</option>
<option value="march">March</option>
<option value="april">April</option>
<option value="may">May</option>
<option value="june">June</option>
<option value="july">July</option>
<option value="august">August</option>
<option value="september">September</option>
<option value="october">October</option>
<option value="november">November</option>
<option value="december">December</option>
</select>
<select name="exp_year"><br/>
<option selected value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>
<option value="2025">2025</option><br/>
</select><br/>
<input type="submit" value="submit">
<input type="reset" value="reset"><br/>
</form>
<----index.php---->
<?php
require 'database.php'; //establishes database connection
require 'core.php'; //uses core.php
include 'login_form.php';//redirects to login_form
?>
<----core.php-----?
<?php
ob_start();
session_start(); // starts the session
$current_file = $_SERVER['SCRIPT_NAME'];//used at login_form
?>
--------------------------------------