2014-06-19 23 views
-1

我很新,请帮我这个.. 我可以只显示名字,但我一定要显示年龄,出生日期也索引页,我已经创建的输入形式平变化的HTML和PHP

check.php我只能发送一个数据,所以我怎么可以给年龄,出生日期也与如何获得,在索引页

的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

可能重复(http://stackoverflow.com/问题/ 11661187/form-serialize-javascript-no-framework) – Ohgodwhy

+0

请缩小你的代码到实际上令人失望的地方。也试着提出一个明确的问题。 –

回答

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/>"; 
?> 
的[形式序列的JavaScript(没有框架)]