Posted: Thu May 13, 2004 6:54 am
Yes but what's the Query? Post the SQL man 
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
$db_server = "#####";
$user = "#####";
$pass = "#####";
$db_private = "#####";
//They are searching...do that for them (we know this from the hidden "go" field in the table)
if ($_POSTї'go'] == "True") {
//Open database server connection
$db_connect = mysql_connect($db_server, $user, $pass, $db);
if (! $db_connect){
Echo "Couldn't connect";
exit;
}
//Open database
if (! mysql_select_db($db_private, $db_connect)){
echo "Error selecting database to use " . mysql_error();
exit;
}
//Build the SQL statement based on POST options
//The basic SQL will select all records
$db_query = "SELECT C_Memory.*, C_VGA.* FROM C_Memory,C_VGA WHERE C_Memory.description LIKE '%whatever%' OR C_VGA.description LIKE '%whatever%'";
//depending on which of the following are filled in (none, some, all)
//the resultset returned will be filtered down
$desc = $_POSTї'description'];
if (strlen($desc) > 0) {
$db_query .= " WHERE description LIKE '%$desc%'";
}
//Run our query
$result1 = mysql_query($db_query, $db_connect);
if (! $result1){
echo mysql_error();
exit;
}
//loop through all the results and display them
echo "<table cellpadding="2" border="1"><tr><td colspan=5>Search Results</td>\r\n";
while($row = mysql_fetch_array($result1)) {
echo "<tr><td>$rowїdescription]</td><td>$rowїprice]</td></tr>\r\n";
} // while
echo "</table>\r\n\r\n";
echo "</body></html>";
//exit out
exit;
}
?>
<table width="500">
<tr>
<td width="500">Search Products </td>
</tr>
</table>
<table>
<form name="mysearch" action="search.php" method="post">
<tr>
<td>Product Description</td><td><input type="text" size="20" value="" name="description"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="hidden" name="go" value="True">
<input type="submit" value="Search">
</td>
</tr>
</table>
</form>Code: Select all
echo $db_query;Code: Select all
$result1 = mysql_query($db_query, $db_connect);
echo $db_query;
if (! $result1){
echo mysql_error();
exit;
}SELECT C_Memory.*, C_VGA.* FROM C_Memory,C_VGA WHERE C_Memory.description LIKE '%whatever%' OR C_VGA.description LIKE '%whatever%' WHERE description LIKE '%samsung%'You have an error in your SQL syntax near 'WHERE description LIKE '%samsung%'' at line 1
Code: Select all
$desc = $_POSTї'description'];
if (strlen($desc) > 0) {
//$db_query .= " WHERE description LIKE '%$desc%'";Altho it does still echo "<table cellpadding=\"2\" border=\"1\"><tr><td colspan=5>Search Results</td>\r\n"; as well ...SELECT C_Memory.*, C_VGA.* FROM C_Memory,C_VGA WHERE C_Memory.description LIKE '%whatever%' OR C_VGA.description LIKE '%whatever%'