【发布时间】:2021-02-04 19:32:05
【问题描述】:
我目前正在为我的网络开发课程做作业。前提是创建一个简单的“音乐会订购网站”。一切都很好,但我一直遇到此错误消息:
Notice: Undefined index: chooseTheAmountOfTickets in C:\xampp\htdocs\webtech\coursework\chapter05\event.php on line 22
这是我的 PHP(注意:我确实在开头有 <?php):
$firstName = $_POST['firstName'];
$phoneNumber = $_POST['phoneNumber'];
$chooseTheAmountOfTickets = $_POST['chooseTheAmountOfTickets'];
$costOfTickets = 35;
$total = $chooseTheAmountOfTickets * $costOfTickets;
print("<p><b>Your total estimated cost is $$total. </b></p>");
?>]
这是我的 HTML:
<form action = "event.php" method = "post">
<p>First Name
<input type = "text" size = "10" name = "firstName">
</p>
<form action = "event.php" method = "post">
<p>Phone Number
<input type = "text" size = "10" name = "phoneNumber">
<form action = "event.php" method = "post" >
<p>Choose the amount of tickets
<input type= "number" method = "post">
</p>
<p><i>Tickets will be $35 each not including tax and fees.</i></p>
<p>
<input type = "submit" value = "Calculate Tickets">
</p>
</form>
</p></td>
<td><b>$35 PER TICKET</b></td>
【问题讨论】:
-
嗨,
chooseTheAmountOfTickets应该是 html 表单中的输入字段。这可能很有趣developer.mozilla.org/en-US/docs/Learn/Forms/… -
您不能也不需要嵌套表单
-
<input type= "number" method = "post">输入没有method属性 -
这不是你的问题,看起来其他人已经解决了这个问题,但是使用这行
print("<p><b>Your total estimated cost is $$total. </b></p>");,你不需要$$total,只需将它设为$total。 $$total 将其转换为变量变量,您可以在此处阅读:php.net/manual/en/language.variables.variable.php
标签: php html html-helper