Jump to content

Php Search Issue


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...