stupidgal
07-27-2013, 06:47 AM
Hi, I'm recently doing some php and html coding. I've ask a lot of people, no one seems to know. In this scenario of mine, I want to display all booking slots regarding this particular prisonerid once the user login. And if the user click "Insert booking", the prisonerid will be automatically in that blank which does not require the user to fill it up again. The problem seems to be lying in the MyBooking.php. If you need more information, please do inform me. How can I do this? I really need help. I'm stuck at this problem for days and my deadline is 5 hours away. Please! Anyone? Please do help me. I will really appreciate it. Thanks in advance!
This is my coding, MyBooking.php
<?php
session_start();
include("Validation.php");
$connect=mysqli_connect("*********","****","","********");
if(mysqli_error($connect))
{
die("Could not connect.");
}
if(isset($_POST["insert_click"]))
{
//Bookingid is auto increment, therefore no need
//$Bookingid=$_POST["BookingID"];
$Prisonerid=$_POST["Prisonerid"];
//http://stackoverflow.com/questions/10895755/populating-a-html-textbox-value-with-php
//http://www.w3schools.com/tags/att_input_readonly.asp
$Prisonerid=$_SERVER["Prisonerid"];
$Prisonerid=array_pop(explode("\\", $Prisonerid));
?>
<input type="text" readonly="readonly" name="uneditablefield" value="<?=$Prisonerid?>"/>
<?php
$Visiting_method=$_POST["VisitingMethod"];
$Visiting_location=$_POST["VisitingLocation"];
$Date=$_POST["Date"];
$Time=$_POST["Time"];
$query=$connect->prepare("insert into Booking(PrisonerID, VisitingMethod, VisitingLocation, Date, Time) values (?,?,?,?,?)");
$query->bind_param('sssss', $Prisonerid, $Visiting_method, $Visiting_location, $Date, $Time);
$query->execute();
}
if(isset($_GET["operation"]))
{
if($_GET["operation"]=="delete")
{
$Bookingid=$_GET["Bookingid"];
$query=$connect->prepare("delete from Booking where BookingID=?");
$query->bind_param('s',$Bookingid);
$query->execute();
}
}
if(isset($_POST["update_click"]))
{
//bookingid is needed to locate the information from updatebooking.php, therefore is needed but won't be show since it is not stated in the prepare statement
$Bookingid=$_POST["BookingID"];
//Prisonerid no need to be changed, therefore no need
//$Prisonerid=$_POST["PrisonerID"];
$Visiting_method=$_POST["VisitingMethod"];
$Visiting_location=$_POST["VisitingLocation"];
$Date=$_POST["Date"];
$Time=$_POST["Time"];
$query=$connect->prepare("update Booking set VisitingMethod=?, VisitingLocation=?, Date=?, Time=? where BookingID=?");
$query->bind_param('sssss', $Visiting_method, $Visiting_location, $Date, $Time, $Bookingid);
$query->execute();
}
//The problem seems to be lying on this statment below especially the WHERE Prisonerid=$_SESSION['Prisonerid']
$query=$connect->prepare("select * from booking WHERE Prisonerid=$_SESSION['Prisonerid']");
$query->execute();
$query->bind_result($Bookingid, $Prisonerid, $Visiting_method, $Visiting_location, $Date, $Time);
?>
<h1>Booking</h1>
<a href ='NewBooking.php'>Insert Booking</a>
<br>
<table border=1>
<tr>
<td>BookingID</td>
<td>PrisonerID</td>
<td>Visiting Method</td>
<td>Visiting Location</td>
<td>Date</td>
<td>Time</td>
<td></td>
</tr>
<?php
while($query->fetch())
{
echo "<tr>";
echo "<td width=60>".$Bookingid."</td>";
echo "<td>$Prisonerid</td>";
echo "<td>$Visiting_method</td>";
echo "<td>$Visiting_location</td>";
echo "<td>$Date</td>";
echo "<td>$Time</td>";
echo "<td><a href='EditBooking.php?operation=edit&Bookingid=".$Bookingid."&PrisonerID=".$Prisonerid."&VisitingMethod=".$Visiting_method."&VisitingLocation=".$Visiting_location."&Date=".$Date."&Time=".$Time."'>edit</a></td>";
echo "<td><a href='MyBooking.php?operation=delete&Bookingid=".$Bookingid."'>delete</a></td>";
echo "</tr>";
}
?>
<a href="Member.php">Member</a> <br>
</table>
This is the coding for the form table, NewBooking.php:
<?php
session_start();
?>
<center><h1>Booking Visit</h1></center>
<form action="MyBooking.php" method="post">
<table align="center" border="1">
<tr>
<td>PrisonerID:</td>
<td><input type="text" name="PrisonerID" value="<?php echo $_SESSION['Prisonerid'];?>" readonly /></td>
</tr>
<tr>
<td>Visiting Method:</td>
<td>
<select name="VisitingMethod">
<option value="Face-to-face">Face-to-face</option>
<option value="Tele-Visit">Tele-Visit</option>
</select>
</td>
</tr>
<tr>
<td>Visiting Location:</td>
<td>
<select name="VisitingLocation">
<option value="Singapore Prison Service (Headquarter)"> Singapore Prison Service (Headquarter)</option>
<option value="Selarang Park Community Supervision Centre"> Selarang Park Community Supervision Centre</option>
</select>
</td>
</tr>
<tr>
<td>Date:</td>
<td>
<input type="text" size="30" name="Date" value="" />
</td>
</tr>
<tr>
<td>Time:</td>
<td>
<select name="Time">
<option value=""> </option>
<option value="15:35:00"> 15:35:00</option>
<option value="16:05:00"> 16:05:00</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="Book Visit" name="insert_click"/></td>
<td>
<input type="submit" value="Previous" name="cancel_click"/>
</td>
</tr>
</table>
</form>
This is the coding for Member.php:
<?php
// Check if session is not registered, redirect back to main page.
// Put this code in first line of web page.
session_start();
if (isset($_SESSION['username'])) {
echo "Welcome ".$_SESSION['username'] ; // When echo'd here, it displays nothing.
echo "<br />".$_SESSION['role'];
echo "<br />".$_SESSION['Prisonerid']."<br />";
?>
<br><a href="MyBooking.php">View Booking</a> <br>
<?php
}else{
header("location:main_form.php");
}
?>
<html>
<body>
<h1>Member Area</h1>
<a href="logout.php">Logout</a>
</body>
</html>
This is my coding, MyBooking.php
<?php
session_start();
include("Validation.php");
$connect=mysqli_connect("*********","****","","********");
if(mysqli_error($connect))
{
die("Could not connect.");
}
if(isset($_POST["insert_click"]))
{
//Bookingid is auto increment, therefore no need
//$Bookingid=$_POST["BookingID"];
$Prisonerid=$_POST["Prisonerid"];
//http://stackoverflow.com/questions/10895755/populating-a-html-textbox-value-with-php
//http://www.w3schools.com/tags/att_input_readonly.asp
$Prisonerid=$_SERVER["Prisonerid"];
$Prisonerid=array_pop(explode("\\", $Prisonerid));
?>
<input type="text" readonly="readonly" name="uneditablefield" value="<?=$Prisonerid?>"/>
<?php
$Visiting_method=$_POST["VisitingMethod"];
$Visiting_location=$_POST["VisitingLocation"];
$Date=$_POST["Date"];
$Time=$_POST["Time"];
$query=$connect->prepare("insert into Booking(PrisonerID, VisitingMethod, VisitingLocation, Date, Time) values (?,?,?,?,?)");
$query->bind_param('sssss', $Prisonerid, $Visiting_method, $Visiting_location, $Date, $Time);
$query->execute();
}
if(isset($_GET["operation"]))
{
if($_GET["operation"]=="delete")
{
$Bookingid=$_GET["Bookingid"];
$query=$connect->prepare("delete from Booking where BookingID=?");
$query->bind_param('s',$Bookingid);
$query->execute();
}
}
if(isset($_POST["update_click"]))
{
//bookingid is needed to locate the information from updatebooking.php, therefore is needed but won't be show since it is not stated in the prepare statement
$Bookingid=$_POST["BookingID"];
//Prisonerid no need to be changed, therefore no need
//$Prisonerid=$_POST["PrisonerID"];
$Visiting_method=$_POST["VisitingMethod"];
$Visiting_location=$_POST["VisitingLocation"];
$Date=$_POST["Date"];
$Time=$_POST["Time"];
$query=$connect->prepare("update Booking set VisitingMethod=?, VisitingLocation=?, Date=?, Time=? where BookingID=?");
$query->bind_param('sssss', $Visiting_method, $Visiting_location, $Date, $Time, $Bookingid);
$query->execute();
}
//The problem seems to be lying on this statment below especially the WHERE Prisonerid=$_SESSION['Prisonerid']
$query=$connect->prepare("select * from booking WHERE Prisonerid=$_SESSION['Prisonerid']");
$query->execute();
$query->bind_result($Bookingid, $Prisonerid, $Visiting_method, $Visiting_location, $Date, $Time);
?>
<h1>Booking</h1>
<a href ='NewBooking.php'>Insert Booking</a>
<br>
<table border=1>
<tr>
<td>BookingID</td>
<td>PrisonerID</td>
<td>Visiting Method</td>
<td>Visiting Location</td>
<td>Date</td>
<td>Time</td>
<td></td>
</tr>
<?php
while($query->fetch())
{
echo "<tr>";
echo "<td width=60>".$Bookingid."</td>";
echo "<td>$Prisonerid</td>";
echo "<td>$Visiting_method</td>";
echo "<td>$Visiting_location</td>";
echo "<td>$Date</td>";
echo "<td>$Time</td>";
echo "<td><a href='EditBooking.php?operation=edit&Bookingid=".$Bookingid."&PrisonerID=".$Prisonerid."&VisitingMethod=".$Visiting_method."&VisitingLocation=".$Visiting_location."&Date=".$Date."&Time=".$Time."'>edit</a></td>";
echo "<td><a href='MyBooking.php?operation=delete&Bookingid=".$Bookingid."'>delete</a></td>";
echo "</tr>";
}
?>
<a href="Member.php">Member</a> <br>
</table>
This is the coding for the form table, NewBooking.php:
<?php
session_start();
?>
<center><h1>Booking Visit</h1></center>
<form action="MyBooking.php" method="post">
<table align="center" border="1">
<tr>
<td>PrisonerID:</td>
<td><input type="text" name="PrisonerID" value="<?php echo $_SESSION['Prisonerid'];?>" readonly /></td>
</tr>
<tr>
<td>Visiting Method:</td>
<td>
<select name="VisitingMethod">
<option value="Face-to-face">Face-to-face</option>
<option value="Tele-Visit">Tele-Visit</option>
</select>
</td>
</tr>
<tr>
<td>Visiting Location:</td>
<td>
<select name="VisitingLocation">
<option value="Singapore Prison Service (Headquarter)"> Singapore Prison Service (Headquarter)</option>
<option value="Selarang Park Community Supervision Centre"> Selarang Park Community Supervision Centre</option>
</select>
</td>
</tr>
<tr>
<td>Date:</td>
<td>
<input type="text" size="30" name="Date" value="" />
</td>
</tr>
<tr>
<td>Time:</td>
<td>
<select name="Time">
<option value=""> </option>
<option value="15:35:00"> 15:35:00</option>
<option value="16:05:00"> 16:05:00</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="Book Visit" name="insert_click"/></td>
<td>
<input type="submit" value="Previous" name="cancel_click"/>
</td>
</tr>
</table>
</form>
This is the coding for Member.php:
<?php
// Check if session is not registered, redirect back to main page.
// Put this code in first line of web page.
session_start();
if (isset($_SESSION['username'])) {
echo "Welcome ".$_SESSION['username'] ; // When echo'd here, it displays nothing.
echo "<br />".$_SESSION['role'];
echo "<br />".$_SESSION['Prisonerid']."<br />";
?>
<br><a href="MyBooking.php">View Booking</a> <br>
<?php
}else{
header("location:main_form.php");
}
?>
<html>
<body>
<h1>Member Area</h1>
<a href="logout.php">Logout</a>
</body>
</html>