0

Hi everyone,

I am new to PHP. I have a problem. I have a simple HTML form where when I select the country from select / option list provided, i want PHP to echo message on country I selected. Also I want PHP include function to list the form specific to that country name (by concatanating). Can someone please help me by pointing where I went wrong. I am new to PHP, self taught and have no idea if this approach is correct. Thanks in advance for anticipated help.

<form name="form1" method="post" action="component_project_in_countries.php">            
<label for="country">View outlets in which country? </label>
<select name="country_chosen" onchange="document.form1.submit()" id="country">
    <option value="">All Middle Eastern Countries</option>
    <option value="Iraq">Iraq</option>
    <option value="Kuwait">Kuwait</option>
    <option value="Bahrain">Bahrain</option>
    <option value="Saudi">Saudi Arabia</option>
    <option value="Qatar">Qatar</option>
    <option value="Oman">Oman</option>
    <option value="Yemen">Yemen</option>          
    <option value="Jordan">Jordan</option>
    <option value="Israel">Israel</option>
</select>
</form>

<br>

<?php 
$country_selected = '';
$country_selected = $_POST['country_chosen'];
echo "You have chosen to view outlets in " . $country_selected;
include ("inc/OutletsIn" . $country_selected .".php";) //Want to concatanate country name and .php to the end
?>

Edited by pritaeas: Changed to thread.

3
Contributors
3
Replies
23
Views
3 Years
Discussion Span
Last Post by Bachu
1

Well it seems like this should be working. Only thing that I see is wrong (in case you haven't found it yet yourself) is the misplacement of your semicolon on line 23. It shouldn't be include ("inc/OutletsIn" . $country_selected .".php";) but include ("inc/OutletsIn" . $country_selected .".php");.

0

Thank you for pointing that out. I managed to figure out and get it working. BUt i have a new porblem. The option value i selected (country name) does not get displayed in the box. How can i hold the chosen value for the session. Please advise. Thank you again.

0

Hai;

Try this

<form name="form1" method="post" action="#">            
<label for="country">View outlets in which country? </label>
<select name="country_chosen" onchange="document.form1.submit()" id="country">
    <option value="">All Middle Eastern Countries</option>
    <option value="Iraq">Iraq</option>
    <option value="Kuwait">Kuwait</option>
    <option value="Bahrain">Bahrain</option>
    <option value="Saudi">Saudi Arabia</option>
    <option value="Qatar">Qatar</option>
    <option value="Oman">Oman</option>
    <option value="Yemen">Yemen</option>          
    <option value="Jordan">Jordan</option>
    <option value="Israel">Israel</option>
</select>
</form>

<br>

<?php 
$country_selected = '';
$country_selected = $_POST['country_chosen'];
echo "You have chosen to view outlets in " . $country_selected;
include ("inc/OutletsIn" . $country_selected .".php"); //Want to concatanate country name and .php to the end
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.