[英]Need help regarding PHP and HTML
我目前正在為我的 Web 開發課程做作業。 前提是創建一個簡單的“音樂會訂購網站”。 一切都很好,但我不斷遇到此錯誤消息:
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>
您沒有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 $35 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">
其中“chooseTheAmountOfTickets”是 php 文件要查找的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.