0

I have a table callled tb_app with fields 'id','name','aic','batchcode'

example: field values '1','james','0001','1'

If type james in the textbox(name) corresponding values for other fields(aic,batchcode) should be displayed in textboxes. Is this possible? can anyone help me...I'm a php beginner ...Please!

Form code:

<form method="post">
 <input type="text" name="names" id="query" />
 <input type="text" name="aic" />
 <input type="text" name="batchcode" />
 <input type="submit" name="show" />
 </form>
Myth
  • 446
  • 7
  • 18

1 Answers1

0

You can do this by Jquery ajax Try in this way by using your exact field names it might help you

Your jquery script should be something like this

 function getvalues()
    {

         var selname = $("input[name='names']:text"").val(); 

            $.ajax({ url: "getuserdata.php",
                data: {"selname":selname},
                type: 'post',
                success: function(output) {
                                $("#aic").val(output);
                                $("#batchcode").val(output);

                }

            });
    }

and your Html code

  <input type="text" name="names" id="query" onblur="getvalues()"/>
  <input type="text" name="aic" id="aic"/>
  <input type="text" name="batchcode" id="batchcode" />

The getuserdata.php

<?php 

include("database connection file here");
$selname = $_POST['selname'];
$query = "SELECT * FROM table_name WHERE youruser_id = $selname";
$res = mysql_query($query);
$rows = mysql_fetch_array($res);
echo $rows['aic']; 
echo $rows['batchcode'];
?>
praveen
  • 286
  • 1
  • 8
  • youruserid is the field name id? – user3227867 Jan 24 '14 at 06:27
  • since you are posting the name in textbox this should be your filed_name in the table – praveen Jan 24 '14 at 06:36
  • y it doesnt show the aic and batchode in their corresponding textboxes when i input a name? – user3227867 Jan 24 '14 at 06:50
  • the selname in the jquery script what is this? my table field name? or the textbox input name? – user3227867 Jan 24 '14 at 07:05
  • Im confused in selname:selname in the script. – user3227867 Jan 24 '14 at 07:06
  • This is just a variable that holds the value of name entered in the textbox – praveen Jan 24 '14 at 07:14
  • can you please explain to me the whole script cause I'm confuse...I'm still new to ajax – user3227867 Jan 24 '14 at 07:28
  • after entering name in the textbox and when that field loses focus the name is captured by jquery and that name is sent as a post request to the getuserdata.php in which we are wirting a sql query to get the corresponding values of that particular name and passing the response back to your php file and the result is being put back in to the exact box of the html form based on the field id – praveen Jan 24 '14 at 07:38
  • I got an error inside the aic and batchcode texboxes...it says. – user3227867 Jan 24 '14 at 07:50
  • Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test\getuserdata.php on line 7
    – user3227867 Jan 24 '14 at 07:51
  • i figured it out the error...now i got this error inside the textbox...Unknown column 'james' in 'where clause'. – user3227867 Jan 24 '14 at 07:59