Hello, i would like to know if its any chance of me being able to retrive data by typing ID, so for example if i type 100 and click on get, i want it to echo the "mobile" number. Can someone please help me with that

Thank you

Sounds straightforward. You're using a form I take it with a database full of mobile numbers, correct?

Create your form with a text box, give it a name attribute of 'myId' or something.

Your php form handling script will then pick up this data like so: $myIdToCheck = $_POST['myId']; check your database for the id: SELECT * FROM mytable WHERE id = '{$myIdToCheck}' The above is extremely lazy and doesn't include security or validation features. Read some online tutorials on $_POST, form submission, SQL statements and recordset manipulation in php. You'll need to read up on these before using this in a live website.

<html>
<head>
</head>
<body>
<?php
$con = mysql_connect("localhost","t","123456");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("t", $con);

if(isset($_POST['ID'])){
mysql_query("SELECT ID FROM table WHERE ID = '".$ID."'LIMIT 1");
} 
$row = mysql_fetch_assoc($result);
echo $row;
mysql_close($con);

?>  
<form method="post" action="">
<font>ID</font> <input type="text" name="ID"/>
<input type="Submit" value="Submit" name="Submit">
</form>
</body>
</html>

I have got this but i am getting an error

Notice: Undefined variable: result in C:\wamp\www\test.php on line 17

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\test.php on line 17


any help please

Dear friend

Assign the $ID
$ID=$_POST;
Use the below code

<html>
<head>
</head>
<body>
<?php
$con = mysql_connect("localhost","t","123456");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("t", $con);

if(isset($_POST['ID'])){
mysql_query("SELECT ID FROM table WHERE ID = '".$_POST['ID']."'LIMIT 1");
} 
$row = mysql_fetch_assoc($result);
echo $row;
mysql_close($con);

?>  
<form method="post" action="">
<font>ID</font> <input type="text" name="ID"/>
<input type="Submit" value="Submit" name="Submit">
</form>
</body>
</html>

Thanks and Regards

Hello Friend,

after trying what you said i am still getting this error

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\test.php on line 17


What i want to do is, just be able to type ID, and it echos the email of that ID.

Thank you

You haven't said what $result is. You can't ask a function to return the contents of the $result object if it doesn't exist.

DO this:

[B]$result = [/B]mysql_query("SELECT ID FROM table WHERE ID = '".$_POST['ID']."'LIMIT 1");

I still don't understand your sql though, why are you retrieving just the ID when you know it already from the post variable??

make sure that your query is properly present inside the if loop.

It can be like this:

if(isset($_POST['ID'])){
mysql_query("SELECT ID FROM table WHERE ID = '".$ID."'LIMIT 1");
$row = mysql_fetch_assoc($result);
echo $row;
mysql_close($con);
}

make sure that your query is properly present inside the if loop.

It can be like this:
[code:
if(isset($_POST)){
mysql_query("SELECT ID FROM table WHERE ID = '".$ID."'LIMIT 1");
$row = mysql_fetch_assoc($result);
echo $row;
mysql_close($con);
}
/code]

ALthough better, that still leaves out declaring the $result object. So it will not work.

After trying the following code, i can confirm that i dont get any errors, but when i insert the ID it comes back and says "Array", i really want to retrive the email, but i just want to see if i am able to retrieve the ID back or not.

If you echo $row , you'll get an array because it's returning a whole row of the resultset, regardless of the fact that there's only one field.
You need to be explicit:

echo $row['id'];

That works like a dream, the reason why i was trying to do this, was so i can see how to retrieve data, so i can enter the ID and it prints email, but how am i able to send an email and not just echo an email.

$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

I have been trying to mess around with the code that you all guys have helped but unfortunately i haven’t been successful.

Thank you for your help.

Have a good day.

This article has been dead for over six months. Start a new discussion instead.