Jump to content
xtekuta

Undefined Variable from ajax to POST

Recommended Posts

I have this ajax function in my PRS.php that whenever i select a value from dropdown, a text field will show an output based on the value which selected. In my console i see there was a POST everytime theres a select value from the drop down. But im getting an error 'Undefined Variable' in ff.php which fetching the POST value from PRS.php  Im new in jQuery so im stuck here in this problem. Any solution for this ? Thanks in advance.

Here is my code in PRS.php

<?php $drp = mysqli_query($conn,"SELECT productcode FROM products"); ?>
                          <td><select name="drpcode" onchange="getState(this.value)" class="form-control name_list"><?php  while ($dp = mysqli_fetch_array($drp)) { ?>
                            <option value="<?php echo $dp['productid']; ?>"><?php echo $dp['productcode']; ?></option><?php } ?></select></td>

                      <td><input type="text" id="brandss" name="brand" placeholder="Brand" class="form-control name_list" required  value=" "></td>

 

My code in ff.php

 

<?php
     require_once("conn.php");


      $id = $_POST['productid'];

         $query = mysqli_query($conn,"SELECT productbrand FROM products WHERE productid = '$id' ");

         while($rs = mysqli_fetch_array($query,MYSQLI_BOTH)) {
         $brand = $rs['productbrand'];

 }

echo $brand;

?>

Share this post


Link to post
Share on other sites

Undefined variable? Which variable? Is it $brand?

Share this post


Link to post
Share on other sites

It's hard to find something that is defined.

  • Your first query selects productcode from products but the value for the options is "productid"
  • The select is named "drpcode" yet you are expecting $_POST[''productid']
4 hours ago, xtekuta said:

Im new in jQuery

What jQuery? What AJAX function?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.