0

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 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

1
  • 1
    That's a MySQL resource. Use something like mysql_fetch_assoc($number), and see if that helps. Commented Jul 29, 2011 at 21:27

1 Answer 1

1

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];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.