I am trying to created a search by categories where users can search other users by name, job, etc... my form in html is:
<td width="37%" align="left"><form id="form1" name="form1" method="post" action="member_search.php">
<span class="tahoma"> Job/Service</span><br />
<input type="text" name="xjob" id="xjob" />
<input name="button" type="submit" id="button" value="Go" />
<input type="hidden" name="listByq" value="by_job" />
</form> </td></tr><tr>
and my php script for it is:
<?php
// Start_session, check if user is logged in or not, and connect to the database all in one included file
include_once("scripts/checkuserlog.php");
?>
<?php
// Connect to database
include_once "scripts/connect_to_mysql.php";
// DEAFAULT QUERY STRING
$queryString = "WHERE email_activated='1' ORDER BY id ASC";
// DEFAULT MESSAGE ON TOP OF RESULT DISPLAY
$queryMsg = "Senior to Newest users";
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////// SET UP FOR SEARCH CRITERIA QUERY SWITCH MECHANISMS
if ((@$_POST['listByq'] == "by_job")) {
$xjob = @$_POST['xjob'];
$xjob = stripslashes($xjob);
$xjob = strip_tags($xjob);
$xjob = eregi_replace("`", "", $xjob);
$xjob = mysql_real_escape_string($xjob);
$queryString = "WHERE job LIKE '%$xjob%' AND email_activated='1'";
$queryMsg = "Showing Members with the Job/Service you searched for";
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QUERY THE MEMBER DATA USING THE $queryString variable's value
$sql = mysql_query("SELECT id, username, firstname, lastname, job, country, state, city, zip FROM myMembers WHERE email_activated='1' ORDER BY id ASC");
$outputList = '';
while($row = mysql_fetch_array($sql2)) {
$id = $row["id"];
$username = $row["username"];
$firstname = $row["firstname"];
if (!$firstname) {
$firstname = $username;
}
$lastname = $row["lastname"];
$job = $row["job"];
$country = $row["country"];
$state = $row["state"];
$city = $row["city"];
$zip = $row["zip"];
$country = $row["country"];
$outputList .= '
<table width="100%" cellspacing="5" cellpadding="5">
<tr>
<td><div style=" height:70px; overflow:hidden;"><a href="profile.php?id=' . $id . '" target="_self">' . $user_pic . '</a></div></td>
<td width="30%"><a href="profile.php?id=' . $id . '" target="_self">' . $firstname . ' ' . $lastname . '</a></td>
<td width="33%">' . $state . ' ' . $city . ' ' . $zip . '</td>
<td width="20%">' . $job . '</td>
</tr>
</table>
<hr />
';
}
?>
<td width="37%" align="left"><form id="form1" name="form1" method="post" action="member_search.php">
<span class="tahoma"> Job/Service</span><br />
<input type="text" name="xjob" id="xjob" />
<input name="button" type="submit" id="button" value="Go" />
<input type="hidden" name="listByq" value="by_job" />
</form> </td></tr><tr>
and my php script for it is:
<?php
// Start_session, check if user is logged in or not, and connect to the database all in one included file
include_once("scripts/checkuserlog.php");
?>
<?php
// Connect to database
include_once "scripts/connect_to_mysql.php";
// DEAFAULT QUERY STRING
$queryString = "WHERE email_activated='1' ORDER BY id ASC";
// DEFAULT MESSAGE ON TOP OF RESULT DISPLAY
$queryMsg = "Senior to Newest users";
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////// SET UP FOR SEARCH CRITERIA QUERY SWITCH MECHANISMS
if ((@$_POST['listByq'] == "by_job")) {
$xjob = @$_POST['xjob'];
$xjob = stripslashes($xjob);
$xjob = strip_tags($xjob);
$xjob = eregi_replace("`", "", $xjob);
$xjob = mysql_real_escape_string($xjob);
$queryString = "WHERE job LIKE '%$xjob%' AND email_activated='1'";
$queryMsg = "Showing Members with the Job/Service you searched for";
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QUERY THE MEMBER DATA USING THE $queryString variable's value
$sql = mysql_query("SELECT id, username, firstname, lastname, job, country, state, city, zip FROM myMembers WHERE email_activated='1' ORDER BY id ASC");
$outputList = '';
while($row = mysql_fetch_array($sql2)) {
$id = $row["id"];
$username = $row["username"];
$firstname = $row["firstname"];
if (!$firstname) {
$firstname = $username;
}
$lastname = $row["lastname"];
$job = $row["job"];
$country = $row["country"];
$state = $row["state"];
$city = $row["city"];
$zip = $row["zip"];
$country = $row["country"];
$outputList .= '
<table width="100%" cellspacing="5" cellpadding="5">
<tr>
<td><div style=" height:70px; overflow:hidden;"><a href="profile.php?id=' . $id . '" target="_self">' . $user_pic . '</a></div></td>
<td width="30%"><a href="profile.php?id=' . $id . '" target="_self">' . $firstname . ' ' . $lastname . '</a></td>
<td width="33%">' . $state . ' ' . $city . ' ' . $zip . '</td>
<td width="20%">' . $job . '</td>
</tr>
</table>
<hr />
';
}
?>