[英]Need help regarding PHP and HTML
I'm currently working on an assignment for my web development course.我目前正在为我的 Web 开发课程做作业。 The premise is to create a simple "concert ordering site".
前提是创建一个简单的“音乐会订购网站”。 Everything is well, but I keep running into this error message:
一切都很好,但我不断遇到此错误消息:
Notice: Undefined index: chooseTheAmountOfTickets in C:\xampp\htdocs\webtech\coursework\chapter05\event.php on line 22
Here's my PHP (Note: I do have the <?php
at the beginning):这是我的 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>");
?>]
Here's my HTML:这是我的 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>
You don't have a form control with a name="chooseTheAmountOfTickets"
value.您没有
name="chooseTheAmountOfTickets"
值的表单控件。 I'm assuming that's what this was meant to be:我假设这就是它的意思:
<input type= "number" method = "post">
You also have multiple forms on the page.页面上还有多个表单。 If these are all supposed to be one form submission, you want something like this:
如果这些都应该是一个表单提交,你想要这样的东西:
<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 $35 each not including tax and fees.</i></p>
<p>
<input type="submit" value="Calculate Tickets">
</p>
</form>
Might find this helpful: https://developer.mozilla.org/en-US/docs/Learn/Forms/Your_first_form可能会发现这有帮助: https : //developer.mozilla.org/en-US/docs/Learn/Forms/Your_first_form
Seems like it's struggling with this line here:似乎它在这里挣扎着这条线:
$chooseTheAmountOfTickets = $_POST['chooseTheAmountOfTickets'];
Looking at your HTML code, for the first two inputs you defined a name for them, but for the final input you did not.查看您的 HTML 代码,对于前两个输入,您为它们定义了名称,但对于最后一个输入,您没有。 All you should have to do is give that input a name like so:
您所要做的就是为该输入命名,如下所示:
<input type= "number" name = "chooseTheAmountOfTickets">
Where "chooseTheAmountOfTickets" is what the php file is looking for.其中“chooseTheAmountOfTickets”是 php 文件要查找的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.