I am new for PHP. I tried to display text box value based on drop down selection. it seems code working. no error display here. But when i change the drop down, text box value shows empty. Even print the data it will display only null.
HTML:-
<select name="cat" id="cat">
<?php
$query1 = "select * from customer_master";
$res1 = mysqli_query($con, $query1);
//while ($row = $res->fetch_assoc())
while($row1 = mysqli_fetch_array($res1)):
?>
<option value="<?php echo $row1[0];?>"><?php echo $row1[2];?></option>
<?php
endwhile;
?>
</select>
<input placeholder="Phone Number" name="phoneNumber" id="pnum" type="text">
Script:-
<script>
$('#cat').click(function(){
var package = $('#cat').val();
$.ajax({
url: 'ajax1.php',
type:'POST',
data: {package: $('#cat').val()},
success: function(data) {
$('#pnum').val(data);
alert(data);
}
});
});
</script>
PHP:-
<?php
include('config.php');
if (isset($_POST['package'])) {
$query = "select * from `customer_master` where Name=" . $_POST['package'];
$result1 = mysqli_query($db, $query);
if (mysqli_num_rows($result1) > 0) {
while ($res = mysqli_fetch_array($result1)) {
echo $res['Start_Ref'];
}
}
die();
}
?>