I am working on a code where one php page sends values to second page and on second page users again adds some values and redirects them to another page where MySQL queries will be executed. I used require function to include second file but when I try to process the third page it gives me undefined index error.
my code is as below: for the first file named display.php
<html lang=en>
<head>
<title> Booking</title>
</head>
<body>
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-6" align="center">
<div class="model-content" align= "center">
<form method="POST" action="payment.php">
<input type="date" name="booking_start" required>
<input type="date" name="booking_end" required>
<input type="time" name="booking_start_time" required>
<input type="time" name="booking_end_time" required>
<?php
//we create a table
echo "<table background='img/parkingimg.png'>";
// create table th
echo "<tr > <th> Parking Slot No </th> <th> Status </th>";
$sql=" select ParkingSlotNo,Status from fleming_dwing ";
$st=$conn->prepare($sql);
$st->execute();
$total=$st->rowCount();//get the number of rows returned
if($total < 1 )
{//if no row was returned
echo "<tr> <td style> No Data: DataBase Empty </td> ";//print out error message
echo "<td> No Data: DataBase Empty </td> ";//print out error message
}
else
{
while($res = $st->fetchObject()){//loop through the returned rows
echo "<tr>";
if($res->ParkingSlotNo and $res->Status=='OCCUPIED')
{
echo "<td> $res->ParkingSlotNo </td> ";
echo "<td> <img src='img/occupied.png'/> </td>";
echo"<td><a href=''> </a> </td>";
}
elseif($res->ParkingSlotNo and $res->Status=='RESERVED')
{
echo "<td> $res->ParkingSlotNo </td> ";
echo "<td> <img src='img/registered.png'/> </td>";
echo"<td><a href=''> </a> </td>";
}
else
{
echo "<td> $res->ParkingSlotNo </td> ";
echo "<td> <img src='img/vacant.png'> </td>";
echo"<td><input name='parkingslot' type='checkbox' value='$res->ParkingSlotNo'></td>";
}
echo"</tr>";
}
}
?>
</table>
<input type="submit" value="Submit">
</form>
</div>
</div>
</body>
</html>
my second file is as below file name: payment.php
<?php
require_once ('navbar.php');
require_once ('dbconfigpdo.php');
$parkingslot = $_POST['parkingslot'];
$booking_start=$_POST['booking_start'];
$booking_end=$_POST['booking_end'];
$booking_start_time=$_POST['booking_start_time'];
$booking_end_time=$_POST['booking_end_time'];
session_start();
$_SESSION['parkingslot'] = $parkingslot;
$_SESSION['booking_start'] = $booking_start;
$_SESSION['booking_end'] = $booking_end;
$_SESSION['booking_start_time'] = $booking_start_time;
$_SESSION['booking_end_time'] = $booking_end_time;
//$_SESSION['price'] = $price;
$a = new DateTime($booking_start_time);
$b = new DateTime($booking_end_time);
$interval = $a->diff($b);
echo $duration=$interval->format("%H");
echo $duration;
$price = '3' * $duration;
echo $price;
echo $parkingslot;
?>
<html>
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
//set your publishable key
Stripe.setPublishableKey('pk_test_ApEdDkstpR0xRuASqSbz0fn9');
//callback to handle the response from stripe
function stripeResponseHandler(status, response) {
if (response.error) {
//enable the submit button
$('#payBtn').removeAttr("disabled");
//display the errors on the form
$(".payment-errors").html(response.error.message);
} else {
var form$ = $("#paymentFrm");
//get token id
var token = response['id'];
//insert the token into the form
form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
//submit form to the server
form$.get(0).submit();
}
}
$(document).ready(function()
{
//on form submit
$("#paymentFrm").submit(function(event)
{
//disable the submit button to prevent repeated clicks
$('#payBtn').attr("disabled", "disabled");
//create single-use token to charge the user
Stripe.createToken({
number: $('.card-number').val(),
cvc: $('.card-cvc').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}, stripeResponseHandler);
//submit from callback
return false;
});
});
</script>
<h1>Payment</h1>
<!-- display errors returned by createToken -->
<span class="payment-errors"></span>
<!-- stripe payment form -->
<form action="paymentsubmit.php" method="POST" id="paymentFrm">
<p>
<label>Name</label>
<input type="text" name="name" size="50" />
</p>
<p>
<label>Email</label>
<input type="text" name="email" size="50" />
</p>
<p>
<label>Card Number</label>
<input type="text" name="card_num" size="20" autocomplete="off" class="card-number" />
</p>
<p>
<label>CVC</label>
<input type="text" name="cvc" size="4" autocomplete="off" class="card-cvc" />
</p>
<p>
<label>Expiration (MM/YYYY)</label>
<input type="text" name="exp_month" size="2" class="card-expiry-month"/>
<span> / </span>
<input type="text" name="exp_year" size="4" class="card-expiry-year"/>
</p>
<button type="submit" id="payBtn">Submit Payment</button>
</form><strong></strong>
</html>
and finally third file is paymentsubmit.php
<?php
require_once ('payment.php');
require_once ('dbconfigpdo.php');
echo $parkingslot;
?>
please help me out
it gives me errors like.
( ! ) Notice: Undefined index: parkingslot in C:\wamp64\www\PROJECT\payment.php on line 5
( ! ) Notice: Undefined index: booking_start in C:\wamp64\www\PROJECT\payment.php on line 6
( ! ) Notice: Undefined index: booking_end in C:\wamp64\www\PROJECT\payment.php on line 7
( ! ) Notice: Undefined index: booking_start_time in C:\wamp64\www\PROJECT\payment.php on line 8
( ! ) Notice: Undefined index: booking_end_time in C:\wamp64\www\PROJECT\payment.php on line 9
I can see and print session variable on second page(payment) but when I submit details to paymentsubmit page I am not able to get values there I mean when I try to print session variable it shows me null in variables and throws me above errors.