I am using the following code to create a form with submit button and after submitting displays the info in the same form ..the code i have written is
<html>
<head>
<script type="text/javascript" src="jquery.js"></script></script>
<script type="text/javascript">
function get(){
$.post('data.php', { name: form.name.value },
function(output) {
$('#age').html(output).show();
$('#number').html(output).show();
}) ;
}
</script>
</head>
<body>
<p>
<form name="form">
name:
<input type ="text" name="name"><input type ="button" value ="Get" onclick="get();">
</form>
<div id="age"></div>
</p>
</body>
</html>
File 2
<?php
Connect to DB
$name = mysql_real_escape_string($_POST['name']);
if ($name==NULL)
echo "please enter an 开发者_StackOverflow社区name!";
else
{
$age= mysql_query("SELECT age FROM parentid WHERE id ='$name'");
$age_num_rows = mysql_num_rows($age);
if ($age_num_rows==0)
echo "id does not exist";
else
{
$age = mysql_result($age, 0);
echo "$name's title is $age'";
}
$number= mysql_query("SELECT number FROM parentid WHERE id ='$name'");
$number_num_rows = mysql_num_rows($number);
if ($name_num_rows==0)
echo "name does not exist";
else
{
$number = mysql_result($number, 0);
echo "$name's number is $number'";
}
}
?>
The output i am getting is
12882's title is xxxx'12882's reportno is Resource id #4'
here 12882's title is xxxx is what is in the database and 12882's reportno is Resource id #4 is not something in the database and i do not know where it is generating the result from
Its a mysql resource, avoid using mysql_result
. Use something like these instead
$row = mysql_fetch_row($age);
echo $name . '\'s title is ' . $row[0];
精彩评论