Possible Duplicate:
PHP, MySQL validation malfunction and search doesn't work?
I have created a form, every thing is working fine, except the search. For example whenever a user input any value in the search box, it will display the result from the database, example name of the employee and etc…
Please see my coding below…
<html>
<head>
<?php
//require_once('student_form.php');
if(isset($_POST['search'])){
$id=$_REQUEST['id'];
$fname=$_POST['fname'];
//connect to the database
include('connection.php');
//-query the database table
$sql=mysql_query("SELECT * FROM members WHERE (FirstName LIKE '". $fname ."%' OR LastName LIKE '". $lname ."%'");
//-run the query against the mysql query function
$result=mysql_query($sql);
if($row=mysql_fetch_array($result)){
$fname=$row['FirstName'];
$lname=$row['LastName'];
/*$email=$row['Email'];
$age =$row['Age'];
$gender=$row['Gender'];
$course = $row['Course'];*/
}
//-display the result of the array
else
{
<?php echo $rows['FirstName']; ?>
<?php echo $rows['LastName']; ?>
}
}
?>
</head>
<body>
<form action="search.php" method="post">
<table>
<tr>
<td><strong>search box</strong></td>
<td><strong>:</strong></td>
<td><input type="text" name="search" value=""size="30"/><input type="submit" name="s1" value="Search"/></td>
</table>
</form>
</body>
</html>
Please note that using the old
mysql_extensions are being deprecated … see the notice at the top of themysql_querydocBut for you to see what the problem is, replace this line :
with this :
You only need to execute
mysql_queryonce and this will now output the error with your query … asmysql_queryreturns aboolean falseif the query fails … see the docs hereAnd please, please take some time to read about SQL Injection
Note this answer will fix your problem – but just fixing it wont help you in the future ….