如何将变量分配给特定日期以便在表单中使用?
我想在用户尝试在特定日期预订太多人时显示警告。我开始编写这段代码,但不知道从哪里开始:
<?php
$spaces = 20;
$num_people = GET('#people');
$message = "Unfortunately we don't have this many spaces avilable on this date. We have a maximum of $spaces.";
if($spaces < $num_people) {
echo $message;
}
&GT;
如何将值$ spaces分配给特定日期并将其链接到表单?这是表格:
<form method="post">
Name:<br>
<textarea id="name"></textarea><br>
<br>
Date leaving:<br>
<br>
<textarea id="date"></textarea><br>
<br>
How many people?:<br>
<textarea id="people"></textarea><br>
<br>
<input type="submit">
答案 0 :(得分:0)
$num_people = GET('#people');
此行应为
$num_people = $_GET['people'];
和
<textarea id="people"></textarea><br>
应该
<textarea id="people" name="people"></textarea><br>
你的方法应该是GET
。由于您要发送GET
请求。
您的代码应如下所示:
<?php
if(isset($_GET['people'])){
$spaces = 20;
$num_people = $_GET['people'];
$message = "Unfortunately we don't have this many spaces avilable on this date. We have a maximum of $spaces.";
if($spaces < $num_people) {
echo $message;
}
}
?>
<form method="get" action="">
Name:<br>
<textarea id="name"></textarea><br>
<br>
Date leaving:<br>
<br>
<textarea id="date"></textarea><br>
<br>
How many people?:<br>
<textarea id="people" name="people"></textarea><br>
<br>
<input type="submit">