Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a php file named new.php.In it,I've stored some data in three variables.

PHP
$sdate = "";
$stime = "";
$seats = "";


When clicked on a button as
<pre lang="HTML"><pre><button onclick="location.href = 'http://localhost/My%20Project/booking.html';" id="myButton" class="float-left submit-button" >Proceed</button>
on this php page,I'm redirected to a new php page named booking.php.(Actually,an html form has been embeded to this php file.It's the reason for redirection.)

All I want to do is,when clicked the above button,the three variables should be passed to the booking.php file too.

Is it possible to do so?

If so,how can I do it?

What I have tried:

<html>
<head>
    <title>Seat Reservation</title>
    <script src="JSFiles/jquery.js" type="text/javascript"></script>
	<script src="JSFiles/ajax.js" type="text/javascript"></script>
    <style type="text/css">
	#holder{	
	 height:600px;	 
	 width:1200px;
	 background-image: url("Images/lay.jpg");
	 border:1px solid #A4A4A4;
	 margin-left:10px;	
	}
	 #place {
	 position:relative;
	 margin:7px;
	 }
     #place a{
	 font-size:0.9em;
	 }
     #place li
     {
         list-style: none outside none;
         position: absolute;   
     }    
     #place li:hover
     {
        background-color:yellow;      
     } 
	 #place .seat{
	 background:url("Images/available.png") no-repeat scroll 0 0 transparent;
	 height:50px;
	 width:50px;
	 display:block;	 
	 }
      #place .selectedSeat
      { 
		background-image:url("Images/booked.png");      	 
      }
	   #place .selectingSeat
      { 
		background-image:url("Images/selected.png");      	 
      }
	  #place .row-3, #place .row-4{
		margin-top:50px;
	  }
	  #place .row-5, #place .row-6{
		margin-top:100px;
	  }
	 #seatDescription{
	 padding:10px;
	 }
	  #seatDescription li{
	  verticle-align:middle;	  
	  list-style: none outside none;
	   padding-left:60px;
	  height:60px;
	  float:left;
	  }
    </style>

	</head>
<body>

<?php
$mysqli = new mysqli("localhost", "root", "", "titan3d");


if (mysqli_connect_error()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$sdate = "";
$stime = "";
$seats = "";

if(isset($_POST['sdate']))
	{
		$sdate = $_POST["sdate"];
	}
if(isset($_POST['stime']))
	{
		$stime = $_POST["stime"];
	}	


$statement = $mysqli->prepare("SELECT bookedseat FROM bookings WHERE sdate = ? AND stime = ?");{


    $statement->bind_param("si", $sdate, $stime);


    if (!$statement->execute()) {
        trigger_error('Error executing MySQL query: ' . $statement->error);
    }


    $statement->bind_result($book);

	$seats = array();
	while ($statement->fetch()) {
		$seats[] = $book;
	}

    $statement->close();
}


$mysqli->close();

?>

<form id="form1">
<script type="text/javascript"
src="JSFiles/show.js">
</script>
<div align="center">
      <h1>Please select your seats.</h1>
       <div id="holder"> 
		<ul  id="place">
        </ul>    
	</div>
	 <div style="width:600px;text-align:center;overflow:auto"> 
	<ul id="seatDescription">
<li style="background:url('Images/available.png') no-repeat scroll 0 0 transparent;">Available Seat</li>
<li style="background:url('Images/booked.png') no-repeat scroll 0 0 transparent;">Booked Seat</li>
<li style="background:url('Images/selected.png') no-repeat scroll 0 0 transparent;">Selected Seat</li>
	</ul>        </div><br><br>
	<div>	
		<input type="button" id="btnShowNew" value="Show Selected Seats" />
		<button onclick="myFunction()">Reselect Seats</button>
		</div>
</div>

    </form>
	
	<div align="center"><button onclick="location.href = 'http://localhost/My%20Project/booking.html';" id="myButton" class="float-left submit-button" >Proceed</button></div>

<script type="text/javascript">
	
        $(function () {
            var settings = {
                rows: 6,
                cols: 15,
                rowCssPrefix: 'row-',
                colCssPrefix: 'col-',
                seatWidth: 80,
                seatHeight: 80,
                seatCss: 'seat',
                selectedSeatCss: 'selectedSeat',
				selectingSeatCss: 'selectingSeat'
            };

            var init = function (reservedSeat) {
                var str = [], seatNo, className;
                for (i = 0; i < settings.rows; i++) {
                    for (j = 0; j < settings.cols; j++) {
                        seatNo = (i + j * settings.rows + 1);
                        className = settings.seatCss + ' ' + settings.rowCssPrefix + i.toString() + ' ' + settings.colCssPrefix + j.toString();
                        if ($.isArray(reservedSeat) && $.inArray(seatNo, reservedSeat) != -1) {
                            className += ' ' + settings.selectedSeatCss;
                        }
                        str.push('<li class="' + className + '"' +
                                  'style="top:' + (i * settings.seatHeight).toString() + 'px;left:' + (j * settings.seatWidth).toString() + 'px">' +
                                  '<a title="' + seatNo + '">' + seatNo + '</a>' +
                                  '</li>');
                    }
                }
                $('#place').html(str.join(''));
            };
					

            var jArray = <?= json_encode($seats) ?>;
            init(jArray);


            $('.' + settings.seatCss).click(function () {
			if ($(this).hasClass(settings.selectedSeatCss)){
				alert('This seat is already reserved');
			}
			else{
                $(this).toggleClass(settings.selectingSeatCss);
				}
            });


            $('#btnShowNew').click(function () {
                var str = [], item;
                $.each($('#place li.' + settings.selectingSeatCss + ' a'), function (index, value) {
                    item = $(this).attr('title');                   
                    str.push(item);                   
                });
                window.alert(str);
            })
        });		
	
		function myFunction() 
		{
			location.reload();
		}
			
</script>
	
</body>
</html>
Posted
Updated 27-Apr-18 6:46am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900