I have small html form as showing below. I can successfully display form values by post method. But I am trying , instead of city, it should display country in the post. ( city and country both are columns fields in mysql table). Is there any way to replace post value city that it should be replace with country from that mysql table ???
<form>
<label>Name</label><input type = text name = "name">
<label>Father</label><input type = text name = "father"><label>City</label><input type = text name = "city">
<input type = submit value = "submit">
</form>
Here is php source code
<?php
if(isset($_POST['submit']))
{
$Name = $_POST['name'];
$Father = $_POST['father'];
$city = $_POST['city'];
}
<table class="center" border=0 width=600>
<tr><td><b>Name : </td><td><?php echo $_POST["name"]; ?>
<tr><td><b>Father : </td><td><?php echo $_POST["Father"]; ?>
<tr><td><b>City : </td><td><?php echo $_POST["city"]; ?>
So, you want to take the city that the user entered into the form, search for that city in your database table, and then display the country that is associated with the city?
That shouldn’t be too difficult. What have you tried so far? Pseudo-code would be something like:
receive form data
query = "select country from mytable where city = ?"
run the query
if there is a result, display it
How will you handle cities that appear in more than one country?
? is the parameter that you would replace with the city name that you’re searching for, once you’ve validated it. I was using ? because that’s how you’d do it with a prepared statement.
Which is line 61? And why are you assigning a value to $_POST['test'] in this code? What is in $city? Does your query run without error when you test it in phpmyadmin?
its first line which I send you, actually my html form has multiple value instead of single, some thing like. thats whty i am facing that error, My html form can post multiple value against one submit
<label>Name</label><input type = text name = "name[]">
<label>Father</label><input type = text name = "father[]">