<?php
$name_user = $_POST['name'];
$city_user = $_POST['the_city'];
$conn = mysqli_connect('127.0.0.1','root','123','people');
mysqli_query($conn, "INSERT INTO people_data (name, the_city) VALUES ('$name_user','$city_user')");
echo "Data has been added:";
echo "<br/>";
echo "Name : $name_user";
echo "<br/>";
echo "The city ";
switch ($city_user)
{
case "01":
echo "London";
break;
case "02":
echo "New York";
break;
case "03":
echo "Bali";
break;
default:
echo "Unknown City";
}
?>
I have run the code, but it returns error: Notice: Undefined index: the_city in /opt/lampp/htdocs/add.php on line 7
I see the name is added, but the city is still blank in the table people_data. I guess the error is in switch statement, but I do not know where's the error.
Expected result in table people_data: the_city contains value like 01 or 02 or 03
I forgot to add the html file, the html file:
<!DOCTYPE HTML>
<HTML>
<body>
<p>
Add Data
<br/>
<form action="add.php" method="post">
Name : <input type="text" name="name" /><br/>
The city :
<select>
<option value = "01">London</option>
<option value = "02">New York</option>
<option value = "03">Bali</option>
</select>
<input type="submit" value="Send">
</form>
</p>
</body>
</HTML>
I run the html file..