domandidomandi 0 Newbie Poster

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();
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.