-1

I am very new to this please help me with this.. i can display only name but i have to display age, dob also in index page as i have created input form

in check.php i can send only one data so how can i send age, dob also and how to get that in index page

index.php

<html>
<head>
<script type='text/javascript'>
function validate(field)
{
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() // Checking if readyState changes
{
if (xmlhttp.readyState==4 && xmlhttp.status==200) // Validation Completed
{
document.getElementById("name").value = xmlhttp.responseText;
}
}
xmlhttp.open("GET","check.php?field="+field+, false);
xmlhttp.send();
}
</script>
</head>
<body>
<form name="gt" id="gt" action="Form_Action.php" method="post" >
<table>
<tr>
<td>Userid</td>
<td><input type='text' name='userid' id='userid' onchange="validate( this.value)"></td>
<td></td></tr>
<tr><td>name</td>
<td><input type='text' name='name' id='name' ></td>
<td></td>
</tr>
<tr><td>age</td>
<td><input type='text' name='age' id='age'></td>
<td></td>
</tr>
<tr><td>dob</td>
<td><input type='text' name='dob' id='dob'></td>
<td></td>
</tr>
</table>
<input type='submit' value='Submit'>
</form>
</body>
</html>

check.php

<?php
include('connect.php');

$field= $_GET['field'];

$res=mysql_query("Select userid,name,age,dob from user where userid='$field' ");
while($row=mysql_fetch_row($res))
{
echo "$row[0]";
}
?>

1 Answers1

0
I don't know if i understood you..without javascript you can simply do as follows:

index.php

 <html>
    <head>
        <title>whatever</title>
    </head>
<body>
 <form name="gt" id="gt" action="check.php" method="post" >
    <!-- notice the form action is in the check.php make sure you give correct location-->
    <table>
    <tr>
        <td>Userid</td>
        <td><input type='text' name='userid' id='userid' ></td>
        <td></td></tr>
    <tr><td>name</td>
        <td><input type='text' name='name' id='name' ></td>
        <td></td>
    </tr>
    <tr><td>age</td>
        <td><input type='text' name='age' id='age'></td>
        <td></td>
    </tr>
    <tr><td>dob</td>
        <td><input type='text' name='dob' id='dob'></td>
        <td></td>
    </tr>
    </table>
 <input type='submit' value='Submit'>
 </form>
</body>
</html>

check.php

<?php
$userid = $_POST['userid'];//since the form has post method in index.php
$name = $_POST['name'];
$age = $_POST['age'];

//You can either put it to database by mysql query or just display as below
echo $userid;
echo "<br/>";
echo $name;
echo "<br/>";
echo $age;
echo "<br/>";
?>
Kushal
  • 98
  • 12