Hi all
i have this code that will search a record from the database
<?php
define ('DB_NAME', 'try1');
define ('DB_USER', 'root');
define ('DB_PASSWORD', '');
define ('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
$term = $_GET['fname'];
$sql = mysql_query("select * from employee where fname like '%$term%'");
$result=mysql_query($sql);
$num=mysql_num_rows($result);
//mysql_close();
$i=0;
while ($i < $num) {
//while ($row = mysql_fetch_array($sql)){
$emp_number=mysql_result($result,$i,"emp_number");
$fname=mysql_result($result,$i,"fname");
$mname=mysql_result($result,$i,"mname");
$lname=mysql_result($result,$i,"lname");
$homeadd=mysql_result($result,$i,"homeadd");
$emailadd=mysql_result($result,$i,"emailadd");
$ofcnum=mysql_result($result,$i,"ofcnum");
$mobilenum=mysql_result($result,$i,"mobilenum");
$homenum=mysql_result($result,$i,"homenum");
$position=mysql_result($result,$i,"position");
$practice=mysql_result($result,$i,"practice");
$projname=mysql_result($result,$i,"projname");
$projmgr=mysql_result($result,$i,"projmgr");
$teamlead=mysql_result($result,$i,"teamlead");
}
?>
<html><br />
<input name="textfield" type="text" value="<?php echo $emp_number; ?>" size="40" />
<br />
<input name="textfield" type="text" value="<?php echo $fname; ?>" size="40" />
<br />
<input name="textfield" type="text" value="<?php echo $mname; ?>" size="40" />
<br />
<input name="textfield" type="text" value="<?php echo $lname; ?>" size="40" />
<br />
<input name="textfield" type="text" value="<?php echo $homeadd; ?>" size="40" />
<br />
<input name="textfield" type="text" value="<?php echo $emailadd; ?>" size="40" />
<br />
<input name="textfield" type="text" value="<?php echo $ofcnum; ?>" size="40" />
<br />
<input name="textfield" type="text" value="<?php echo $mobilenum; ?>" size="40" />
<br />
<input name="textfield" type="text" value="<?php echo $homenum; ?>" size="40" />
<br />
<input name="textfield" type="text" value="<?php echo $position; ?>" size="40" />
<br />
<input name="textfield" type="text" value="<?php echo $practice; ?>" size="40" />
<br />
<input name="textfield" type="text" value="<?php echo $projname; ?>" size="40" />
<br />
<input name="textfield" type="text" value="<?php echo $projmgr; ?>" size="40" />
<br />
<input name="textfield" type="text" value="<?php echo $teamlead; ?>" size="40" />
<input type="submit" name="edit" value="Edit" />
<input type="submit" name="update" value="Update" />
</html>
but when i click my search button, i got this error
( ! ) Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\log-in\search.php on line 22
Call Stack
# Time Memory Function Location
1 0.0015 393280 {main}( ) ..\search.php:0
2 0.0182 402952 mysql_query ( ) ..\search.php:22
( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\wamp\www\log-in\search.php on line 23
Call Stack
# Time Memory Function Location
1 0.0015 393280 {main}( ) ..\search.php:0
2 0.0191 403200 mysql_num_rows ( ) ..\search.php:23
( ! ) Notice: Undefined variable: emp_number in C:\wamp\www\log-in\search.php on line 48 Call Stack #TimeMemoryFunctionLocation 10.0015393280{main}( )..\search.php:0 " size="40" />
( ! ) Notice: Undefined variable: fname in C:\wamp\www\log-in\search.php on line 50 Call Stack #TimeMemoryFunctionLocation 10.0015393280{main}( )..\search.php:0 " size="40" />
( ! ) Notice: Undefined variable: mname in C:\wamp\www\log-in\search.php on line 52 Call Stack #TimeMemoryFunctionLocation 10.0015393280{main}( )..\search.php:0 " size="40" />
( ! ) Notice: Undefined variable: lname in C:\wamp\www\log-in\search.php on line 54 Call Stack #TimeMemoryFunctionLocation 10.0015393280{main}( )..\search.php:0 " size="40" />
( ! ) Notice: Undefined variable: homeadd in C:\wamp\www\log-in\search.php on line 56 Call Stack #TimeMemoryFunctionLocation 10.0015393280{main}( )..\search.php:0 " size="40" />
( ! ) Notice: Undefined variable: emailadd in C:\wamp\www\log-in\search.php on line 58 Call Stack #TimeMemoryFunctionLocation 10.0015393280{main}( )..\search.php:0 " size="40" />
( ! ) Notice: Undefined variable: ofcnum in C:\wamp\www\log-in\search.php on line 60 Call Stack #TimeMemoryFunctionLocation 10.0015393280{main}( )..\search.php:0 " size="40" />
( ! ) Notice: Undefined variable: mobilenum in C:\wamp\www\log-in\search.php on line 62 Call Stack #TimeMemoryFunctionLocation 10.0015393280{main}( )..\search.php:0 " size="40" />
( ! ) Notice: Undefined variable: homenum in C:\wamp\www\log-in\search.php on line 64 Call Stack #TimeMemoryFunctionLocation 10.0015393280{main}( )..\search.php:0 " size="40" />
( ! ) Notice: Undefined variable: position in C:\wamp\www\log-in\search.php on line 66 Call Stack #TimeMemoryFunctionLocation 10.0015393280{main}( )..\search.php:0 " size="40" />
( ! ) Notice: Undefined variable: practice in C:\wamp\www\log-in\search.php on line 68 Call Stack #TimeMemoryFunctionLocation 10.0015393280{main}( )..\search.php:0 " size="40" />
( ! ) Notice: Undefined variable: projname in C:\wamp\www\log-in\search.php on line 70 Call Stack #TimeMemoryFunctionLocation 10.0015393280{main}( )..\search.php:0 " size="40" />
( ! ) Notice: Undefined variable: projmgr in C:\wamp\www\log-in\search.php on line 72 Call Stack #TimeMemoryFunctionLocation 10.0015393280{main}( )..\search.php:0 " size="40" />
( ! ) Notice: Undefined variable: teamlead in C:\wamp\www\log-in\search.php on line 74 Call Stack #TimeMemoryFunctionLocation 10.0015393280{main}( )..\search.php:0 " size="40" />