I am creating a webpage in which person enters a name and the marketplaces registered under that name is displayed in a dropdown. Here's part of my code
<form name="login" action="index_submit" method="get" accept-charset="utf-8">
<ul>
<li>
<label for="seller">Seller Name/ID</label>
<input type="text" id="username" placeholder="Seller Username/ID" required>
</li>
<?php
?>
<li>
<label for="marketplace">Choose a marketplace</label>
<select name="url" onchange="menu_goto(this.form)">
<?php
include ('config.php');
$username = $_POST['username'];
$query = "SELECT Marketplace FROM Details WHERE Seller_name='$username' OR Seller_ID='$username'";
$result = mysql_query($dbcon, $query) or die('error getting data');
while ($row = mysql_fetch_array($result)){
echo "<option value="marketplace1">" . $row['Marketplace'] . "</option>";
}
?>
</select>
</li>
but when i'm running the .php file i'm getting a screen with results of till the php script is encountered, the html code below it remains untouched. I'm new with this. I'm unable to detect the error (if any) in my code. The config.php file is just a connection established with my database (no more code included in it).Also, the rest of my code works fine if i remove the php script from the code and my webpage is then displayed. I am guessing the problem is with my php script.
EDIT: I used the following answered by someone: on username input field, put a javascript function and then use ajax to call server side code and then append result of that as option with url field. like following.
<form name="login" action="index_submit" method="get" accept-charset="utf-8">
<ul>
<li>
<label for="seller">Seller Name/ID</label>
<input type="text" onchange="ajaxCall(this.value)" id="username" placeholder="Seller Username/ID" required>
</li>
<?php
?>
<li>
<label for="marketplace">Choose a marketplace</label>
<select name="url" onchange="menu_goto(this.form)">
</select>
</li>
javascript function should be like this.
<script>
function ajaxCall(val)
{
$.post('abc.php',{'username':val},function(res){
$.('#url').html(res);
});
}
</script>
abc.php will be following.
<?php
include ('config.php');
$username = $_POST['username'];
$query = "SELECT Marketplace FROM Details WHERE Seller_name='$username' OR Seller_ID='$username'";
$result = mysql_query($dbcon, $query) or die('error getting data');
$res='';
while ($row = mysql_fetch_array($result)){
$res .='<option value="marketplace1">' . $row['Marketplace'] . '</option>';
}
echo $res;
?>
and my whole code is getting executed now, but i'm still not getting any value in my dropdown list.(it appears blank and yes, i have values in my database).