Results 1 to 1 of 1

Thread: how display a value (prisonerid) from database into a form table?

  1. #1
    Join Date
    Jul 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how display a value (prisonerid) from database into a form table?

    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
    Code:
    <?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:
    Code:
    <?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:
    Code:
    <?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>
    Last edited by traq; 07-27-2013 at 06:33 PM. Reason: Formatting / obfuscated DB credentials

Similar Threads

  1. Resolved Form-MySQL-Display table on site
    By liamallan in forum PHP
    Replies: 6
    Last Post: 02-14-2010, 11:42 AM
  2. From an html form in https:// url save the credit card data in a mysql database table
    By leonidassavvides in forum MySQL and other databases
    Replies: 4
    Last Post: 05-26-2009, 02:15 AM
  3. display data from database
    By avneet in forum PHP
    Replies: 1
    Last Post: 03-10-2008, 05:41 AM
  4. Replies: 22
    Last Post: 05-30-2007, 11:04 PM
  5. Alphabetic Database Display
    By amvmendoza in forum ASP
    Replies: 0
    Last Post: 11-11-2004, 06:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •