Jump to content

Php Search Issue


subha rr

Recommended Posts

Hi.....below the php code for search name and date

<?phpif($block == false){include "header.php";$nam = $_POST['nam'];$datt = $_POST['datt'];?><form method = POST action = "search.php">Name <input type=text name=nam value = "%%">Date <input type=text name=datt value = "<?php echo($datt);?>"><input type=submit name=submit value="Search"></form><?php$sub = $_POST['submit'];if($sub == ""){ if($nam!="" && $dat!=""){ $t = "select * from timesheet where name like 'nam' && dat like '$datt'"; } else if($nam!="" || $datt!=""){ $t = "select * from timesheet where name like 'nam' || dat like '$datt'"; } else{ $t = "select * from timesheet order by id desc"; } $res= mysql_query($t,$link); echo "<table align=center cellpadding=4px cellspacing=4px> <tr align=center><td>ID</td><td>Name</td><td>Date</td><td>Total working Hours</td></tr>"; $a=1; while($line=mysql_fetch_row($res)) { echo "<tr align='center'><td>$a</td><td>$line[1]</td><td>$line[2]</td><td>$line[3]</td></tr>"; $a++; } echo "</table><br><br>";}else{ echo "Please enter the search details";}}?>
this code cannot display the search details...Pls help me
Link to comment
Share on other sites

"select * from timesheet where name like 'nam' && dat like '$datt'";

"like" clause is supposed to be used with jolly charcters "%"so queries should look like:

"... dat like '%$datt%'";

or

"...dat like 'datt%'";

or

"... dat like '%$datt'";

according to the part of search key string you want to matchactually I see you pass "%%" through html form but you'd better control it with php code.regards

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...