Why won't this code work?
Code: Select all
$sql=mysql_query("SELECT * FROM data WHERE (rccfname LIKE '%namesearch%') OR (rcclname LIKE '%namesearch%') OR (clientfname LIKE '%namesearch%') OR (clientlname LIKE '%namesearch%')", $link) or die(mysql_error());Solution Code to Below
Code: Select all
<?php
$sql=mysql_query("SELECT * FROM data where bldg LIKE '%$areasearch'", $link) or die(mysql_error());
?>There are 4 different columns I want to search from. I'm trying to build the code one by one for each search. Or if possible, put it all into a nested If or something.
I've using the following code, but I can't get it to generate any results.
Errors are enabled.
Code: Select all
<?php
//Other Code above here...
// Begin submit form variables
$areasearch = $_POST['areasearch'];
$bldgsearch = $_POST['bldgsearch'];
$namesearch = $_POST['namesearch'];
$rccidsearch = $_POST['rccidsearch'];
// End submit form variables
// Connect to DB
$link = mysql_connect('localhost','blah','blah') or die ('Could not connect to mySQL server!: ' .mysql_error() );
mysql_select_db('quickincidents', $link) or die ('Could not select DB!: ' .mysql_error() );
// Search by Area
$sql=mysql_query("SELECT bldg FROM data where bldg = '$areasearch'", $link) or die(mysql_error());
$bg = '#FFFFFF'; //set background color
while ( $row = mysql_fetch_array($sql)) {
$bg = ($bg=='#FFFFFF' ? '#D8D8D8' : '#FFFFFF'); //switch background color
echo '<tr bgcolor="',$bg,'">';
print "<td>" . $row['rccfname'] . "</td>";
print "<td>" . $row['rcclname'] . "</td>";
print "<td>" . $row['rccid'] . "</td>";
print "<td>" . $row['rccemail'] . "</td>";
print "<td>" . $row['clientfname'] . "</td>";
print "<td>" . $row['clientlname'] . "</td>";
print "<td>" . $row['bldg'] . "</td>";
print "<td>" . $row['dormphone'] . "</td>";
print "<td>" . $row['altphone'] . "</td>";
print "<td>" . $row['clientemail'] . "</td>";
print "<td>" . $row['probleminfo'] . "</td>";
}
//End Search by Area
?>
<!--Make Page/Table headers-->
<h1><strong>ResNet Quick Incident Database Results </strong></h1>
<table border="1" width="100%" cellspacing="2" cellpadding="2">
<tr>
<th> Consultant Fname </th>
<th> Consultant Lname </th>
<th> Consultant ID </th>
<th> Consultant E-Mail </th>
<th> Client Fname </th>
<th> Client Lname </th>
<th> Client Bldg </th>
<th> Client Dorm Phone </th>
<th> Client Alt Phone </th>
<th> Client E-Mail </th>
<th> Problem Info </th>
</tr>
</table>
<p><a href="search.html">Back to Search Page </a></p>
</body>
</html>Code: Select all
tags for readability.[/color]Code: Select all
<?php
?>Code: Select all
<?php
?>