Dear friends,
I want to get my field value from database based on other input in my form. For example, consider there are 2 inputs in a from. (Family name and Age). If a user enters family name, the program should get age based on his family name from the database before submitting the form.
I’m nearly sure, it is possible with the help of java script.
<form name = "autofill" method="post">
<input type="text" name="family-name" id="family-name" />
<input type="text" name="age" id="age"/>
<input type="submit" name="submit" value="submit"/>
</form>
I guess my php code should be something like this:
<?php
$family_name = $_GET['family_name'];
$sql = "SELECT age FROM users WHERE family_name = '$family_name'";
$return = mysqli_query($db, $sql);
$rows = mysqli_fetch_array($return);
echo json_encode($rows);
?>
I have jquery plugin in my file.
How can I do it?
Thanks in advance