I'm currently working on an assignment for my web development course. 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):
$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:
<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. 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