PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a advance search form where users can put in either fname, lname, department or email address to look up for an employee. I want to make sure they at least choose one option before they submit the form. My code looks like this :-
<?php
if ($post == "yes") {
MySQL Query goes here!!
$dbResult = pg_query($query);
if(!pg_numrows($dbResult))
{
print("<tr><td>Sorry Nothing was found matched your query:</td>/n
</tr>");
}
else
{
print("<p><table border="0" cellpadding="5" cellspacing="4" summary="">");
print("<tr>
<td width="220"colspan="2"><strong>Name</strong></td>
<td width="280"><strong>Department</strong></td>
<td width="150"><strong>Phone</strong></td>
</tr>");
}
{
$n="1";
while($row = pg_fetch_row($dbResult))
{ // These 2 variables are hidden values
$empid = $row[0];
$rank = $row[B];
// Writes the search results by the designated rows (first name, last name, phone and department name)
$fname = $row[1];
$lname = $row[2];
$phone = $row[3];
$name = $row[5];
print ( "<tr>
<td width="2">$n.". "</td>
<td width="220"><a href = "employee_details_page.php?employeeID= $empid ">$lname, $fname</a></td>
<td width="280">$name</td>
<td width="150">269-$phone</td>
</tr>");
$n++;
}
print ("</table>");
}
print ("</td></tr></table>");
}
?>
I did not put my sql query because it will make the page even longer. I want to know how to make the page to return to the same search page if none of search field was submitted. I would like to Thank in advance on your feedback.
I would like to thank you for your fast reply, I tried placing your code at the top of my page but still if I submit the form without even entering any data, it populates every single result. If you can see below, I have provided the code for mysql query.. which i did not before.. I am not sure if this will of much help but I hope it will help you understand the picture better
at the top of my page but still I am getting the same thing. The page is populating all the results. I would really appreciate any feedback. Thanks a lot
I'm seeing Get's in your SQL but you mentioned using POST in your orginal code for the form which is it. You might want to just change the $_POST to $_REQUEST (less secure) or $_GET if you know it's a GET.
I am sorry It was my mistake, I had everything in _GET. I have changed everything to _GET but this time there is a slight improvement, the page is not populating all the result but either when I put in something in the search box it does not search...
I have a advance search form where users can put in either fname, lname, department or email address to look up for an employee. I want to make sure they at least choose one option before they submit the form.
Why don't you just use a small bit of JavaScript before the form is submitted to make sure the form has some info?
...I see that in your code. However, there is a difference between empty() and isset().
Example: http://www.example.com/index.php?id=
Here, isset($_GET['id']) evaluates to TRUE but empty($_GET['id']) evaluates to FALSE.
...also empty() will return TRUE if the value is 0 (zero) so be careful how you use it. isset() will return TRUE if the variable exists regardless of it's contents.
I normally combine isset() and strlen() to check if a variable has any contents...