Need database query help...

A

Anonymous

Guest
Hi everyone -

I'm still relatively new to PHP and MySQL, so bear with me please...

I'm trying to execute a very basic database query (although it seems quite the contrary!)...Here is the relevent snippet of code from my PHP file:


<form method="post" action="<? echo $PHP_SELF; ?>">


<br>For a Phone Number, please enter the:

<br><br>Name: <input type="text" name="name">

<br><br><input type="submit" value="Get Phone Number">
<br><br>



<?

mysql_connect("localhost","username","password");

mysql_select_db("MyDatabase");

$query = "SELECT phone_number FROM phone_list WHERE name LIKE '%$name%'";
$result = mysql_query($query);

if (isset($name))
echo "The phone number for $name is $result.";

?>



The database query works when I test it in phpMyAdmin, which leads me to believe it is a php coding problem....Thanks in advance for any help you can provide..:)

R.J.
 
Echo your query and see if it looks like you expect. Then paste it into a MySQL client (NOT phpMyAdmin) and see if you get the results you expect.
 
oh man, i havent been to this website in a while.....

try this:

$query = "SELECT phone_number FROM phone_list WHERE name LIKE '%".$_REQUEST['name']."%'";

:)
 
Back
Top