需要有关 PHP 和 HTML 的帮助
Need help regarding PHP and HTML
我目前正在为我的网络开发课程做作业。前提是创建一个简单的“音乐会订购站点”。一切都很好,但我将 运行 保存到此错误消息中:
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 each not including tax and fees.</i></p>
<p>
<input type = "submit" value = "Calculate Tickets">
</p>
</form>
</p></td>
<td><b> PER TICKET</b></td>
您没有具有 name="chooseTheAmountOfTickets"
值的表单控件。我假设这就是本意:
<input type= "number" method = "post">
页面上还有多个表单。如果这些都应该是一个表单提交,你想要这样的东西:
<form action="event.php" method="post">
<p>First Name
<input type="text" size="10" name="firstName">
</p>
<p>Phone Number
<input type="text" size="10" name="phoneNumber">
</p>
<p>Choose the amount of tickets
<input type="number" name="chooseTheAmountOfTickets">
</p>
<p><i>Tickets will be each not including tax and fees.</i></p>
<p>
<input type="submit" value="Calculate Tickets">
</p>
</form>
可能会觉得这有帮助:https://developer.mozilla.org/en-US/docs/Learn/Forms/Your_first_form
似乎正在为这条线苦苦挣扎:
$chooseTheAmountOfTickets = $_POST['chooseTheAmountOfTickets'];
查看您的 HTML 代码,您为前两个输入定义了名称,但没有为最后一个输入定义名称。您所要做的就是为该输入命名,如下所示:
<input type= "number" name = "chooseTheAmountOfTickets">
php 文件要查找的是“chooseTheAmountOfTickets”。
我目前正在为我的网络开发课程做作业。前提是创建一个简单的“音乐会订购站点”。一切都很好,但我将 运行 保存到此错误消息中:
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 each not including tax and fees.</i></p>
<p>
<input type = "submit" value = "Calculate Tickets">
</p>
</form>
</p></td>
<td><b> PER TICKET</b></td>
您没有具有 name="chooseTheAmountOfTickets"
值的表单控件。我假设这就是本意:
<input type= "number" method = "post">
页面上还有多个表单。如果这些都应该是一个表单提交,你想要这样的东西:
<form action="event.php" method="post">
<p>First Name
<input type="text" size="10" name="firstName">
</p>
<p>Phone Number
<input type="text" size="10" name="phoneNumber">
</p>
<p>Choose the amount of tickets
<input type="number" name="chooseTheAmountOfTickets">
</p>
<p><i>Tickets will be each not including tax and fees.</i></p>
<p>
<input type="submit" value="Calculate Tickets">
</p>
</form>
可能会觉得这有帮助:https://developer.mozilla.org/en-US/docs/Learn/Forms/Your_first_form
似乎正在为这条线苦苦挣扎:
$chooseTheAmountOfTickets = $_POST['chooseTheAmountOfTickets'];
查看您的 HTML 代码,您为前两个输入定义了名称,但没有为最后一个输入定义名称。您所要做的就是为该输入命名,如下所示:
<input type= "number" name = "chooseTheAmountOfTickets">
php 文件要查找的是“chooseTheAmountOfTickets”。