我如何在另一页上回显以下结果。我需要它来回应用户选择的内容。
<strong>Return</strong>
<select id="Date" name="Date">
<option value="0">--Select date/time--</option>
<?php foreach ($return as $return) { ?>
<option value="<?php echo $return; ?>"><?php echo $return; ?></option>
<?php } ?>
由于
用户进行选择的完整代码。他们在这个页面上选择的信息是我想在另一页上回应的信息。
<!DOCTYPE html>
<?php
session_start();
?>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>
</title>
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<link rel="stylesheet" href="my.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
</script>
<script src="my.js">
</script>
<!-- User-generated css -->
<style>
</style>
<!-- User-generated js -->
<script>
try {
$(function() {
});
} catch (error) {
console.error("Your javascript has an error: " + error);
}
</script>
</head>
<body>
<!-- Home -->
<div data-role="page" id="page1">
<div data-theme="a" data-role="header">
<a data-role="button" data-theme="d" href="login.html" data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
Back
</a>
<a data-role="button" href="index.html" data-icon="home" data-iconpos="right" data-theme="d"class="ui-btn-right">
Home
</a>
<h3>
Book Car
</h3>
</div>
<div data-role="content">
<h3>
Select date/time:
</h3>
<br />
<?php
{
mysql_connect("localhost" , "" , "") or die (mysql_error());
mysql_select_db("") or die(mysql_error());
$query = "SELECT `book_time`, `book_date`, `return_time`, `return_date` FROM `Rental`";
//executes query on the database
$result = mysql_query ($query) or die ("didn't query");
//this selects the results as rows
$num = mysql_num_rows ($result);
$return = array();
$rent = array();
while($row=mysql_fetch_assoc($result))
{
$rent[] = $row['book_date'].' '.$row['book_time'];
$return[] = $row['return_date'].' '.$row['return_time'];
}
}
?>
<form method="post" action="car.php">
<strong>Rent out</strong>
<select id="Date" name="Date">
<option value="0">--Select date/time--</option>
<?php foreach ($rent as $rent) { ?>
<option value="<?php echo $rent; ?>"><?php echo $rent; ?></option>
<?php } ?>
</select>
<br />
<strong>Return</strong>
<select id="Date" name="Date">
<option value="0">--Select date/time--</option>
<?php foreach ($return as $return) { ?>
<option value="<?php echo $return; ?>"><?php echo $return; ?></option>
<?php } ?>
</select>
<br />
<br />
<input type="submit" name="Submit" value="Book" />
</form>
</div>
</div>
</body>
</html>
答案 0 :(得分:3)
表格基础101:
~~~index.php~~~
<form action='the_new_page.php' method='POST'>
<input type='text' name='first_thing'>
<input type='hidden' name='some_hidden_guy' value='1'>
<input type='submit' name='submit_button' value='submit'>
</form>
当用户提交上述表单时,浏览器会将其定向到the_new_page.php
,the_new_page.php
将知道所有表单信息。
表单会传递name
和value
,而不是您需要知道的其他内容。 id
非常适用于html目的,并且作为HTML中的规则,不允许您拥有多个具有相同ID的元素。人们通常会混淆地将表单字段的id命名为与表单字段的“名称”相同,这使得学习各自的意思非常困难。
因此,在提交表格后,它将转到您的第二页,然后您可以这样做:
~~~the_new_page.php~~~
//You can then do
echo $_POST['some_hidden_guy'] //will be 1
echo $_POST['first_thing'] //Will be whatever you inserted into the text box
如果您希望表单返回当前页面,只需将action
留空即可<form action=''>
或<form method='POST'>
为多个页面保留相同的信息!
现在,这是一个非常非程序员的方法,因为你应该找到一种不必在任何页面上重复相同代码的方法。如果你不这样做,我现在就警告你。维护这个应用程序将成为一场噩梦,因为你每次想要添加新字段时都必须编辑每一页。关于这个例子。
现在,假设您已将信息传递给car.php,您现在想在carplan.php上使用它。
~~~car.php~~~
<form action='carplan.php' method='GET or POST, whichever it is you be using using'>
<input type='hidden' name='Date' value='<?php echo $_GET['date'] ?>'>
<input type='hidden' name='some_other_thing' value='<?php echo $_GET['some_other_thing'] ?>'>
<option name='plan_id'>
<?php foreach($plans as $plan): ?>
<select value='<?php echo $plan['id'] ?>'><?php echo $plan['name'] ?>'>
<?php endforeach; ?>
</option>
<input type='submit' name='submit' value='Get That Plan'>
</form>
最后是关于carplan.php
~~~carplan.php~~~
<form action='the_next_step.php' method='GET or POST, whichever you be using'>
<input type='hidden' name='Date' value='<?php echo $_GET['date'] ?>'>
<input type='hidden' name='some_other_thing' value='<?php echo $_GET['some_other_thing'] ?>'>
<input type='hidden' name='plan_id' value='<?php echo $_GET['plan_id']?>'>
<input type='submit' name='submit' value='The next step!'>
</form>
答案 1 :(得分:0)
你可以通过......来回应这个。
echo $_GET['Date'];
或强>
echo $_POST['Date'];
或强>
echo $_REQUEST['Date'];