如何将一个PHP中的变量值传递给另一个PHP文件? [英] How do I pass the variable values in one PHP to another PHP file?

查看:132
本文介绍了如何将一个PHP中的变量值传递给另一个PHP文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为new.php的php文件。在其中,我将一些数据存储在三个变量中。



I have a php file named new.php.In it,I've stored some data in three variables.

$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>

在这个php页面上,我被重定向到一个名为booking.php的新php页面。(实际上,一个html表单已经嵌入到这个php文件中。这是重定向的原因。)



我想要做的就是,当点击上面的按钮时,三个变量也应传递给booking.php文件。



是否可以这样做?



如果是这样,我该怎么办?



我尝试过:



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>

推荐答案

sdate = ;
sdate = "";


stime = ;
stime = "";


席位 = ;





单击按钮时



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>

在这个php页面上,我被重定向到一个名为booking.php的新php页面。(实际上,一个html表单已经嵌入到这个php文件中。这是重定向的原因。)



我想要做的就是,当点击上面的按钮时,三个变量也应传递给booking.php文件。



是否可以这样做?



如果是这样,我该怎么办?



我尝试过:



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


这篇关于如何将一个PHP中的变量值传递给另一个PHP文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆