Jump to content


Photo

Can't search MySQL DB


  • Please log in to reply
1 reply to this topic

#1 turbocueca

turbocueca
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 11 April 2006 - 09:30 PM

A code that works:

<form method="POST" action="">
Search Word: <input type="text" name="query">
<input type="SUBMIT" value="Search!">
</form>

<?
include 'db.php';
if (isset($_POST['query'])) {
$result = mysql_query("SELECT name,system FROM usbextreme WHERE name LIKE '%$query%'") or die (mysql_error());

while(list($column1, $column2)=mysql_fetch_array($result)){

echo "Result: $column1, $column2 <br />";
}

}
?>

My code:

<form method="POST" action="">
 Search:<input type="text" name="query">
 <input type="SUBMIT" value="Search!">
</form>
<?php    if (isset($_POST['query'])) 
        {
        include 'db.php';
        $execute=mysql_query("SELECT name,system,work_status,postedby,comments FROM usbextreme WHERE name LIKE '%query%'") or die (mysql_error());
        while (list($name,$sys,$stat,$user,$comment)=mysql_fetch_array($execute))
        {
        echo "$name   $sys   $stat   $user   $comment";
        }
        } else
        {
        echo "You didn't press the button!";
        }
?>


Can someone please tell me what's wrong with my code, 'cause it doesn't search anything.

#2 turbocueca

turbocueca
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 12 April 2006 - 09:04 AM

problem solved, had '%query%' instead of '%$query%'




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users