Page 1 of 1
search query
Posted: Tue Nov 16, 2004 4:02 am
by ecaandrew
Code: Select all
$result = mysql_query("SELECT * FROM templates WHERE
author='".$_POST['$author']."' OR id='".$_POST['$itemid']."'
OR category='".$_POST['$category']."' AND price ".$_POST['$price']."
LIMIT ".(($current - 1) * $count).", " . $count);
my search query is not working for some reason, i get no errors, but i mean nothing shows up correct. anyone plaese

Posted: Tue Nov 16, 2004 4:07 am
by timvw
what does mysql_error tell you?
1 - you don't validate posted values.
2 - ' AND price ".$_POST['$price']." needs a comparision operator between price and $_POST price.
Posted: Tue Nov 16, 2004 4:38 am
by Chris Corbyn
Could you post a bit more code please? If there are no errors it is likely that your query is looking for the wrong thing (mis-typed variables etc)
test it like this
Posted: Tue Nov 16, 2004 4:42 am
by nashhill
you should test it on PhpMyAdmin
or some soft for use in mysql
That you will get the answer quickly!
Posted: Tue Nov 16, 2004 4:46 am
by Chris Corbyn
Hmm... looking at the post by timvw my last post is a bit redundant. Number 2 in timvw's post will be the cause sorry
Posted: Tue Nov 16, 2004 4:21 pm
by ecaandrew
now heres the search form
index.php
---------------------------------------------------------------------------------
Code: Select all
<form action="/search/index.php" method="post">
<tr>
<td style="padding-left:30">Author: </td>
<td><input type="text" name="author" size="15" maxlength="256"></td>
</tr>
<tr>
<td style="padding-left:30">Item No: </td>
<td><input type="text" name="itemid" size="15" maxlength="256"></td>
</tr>
<tr>
<td style="padding-left:30">Price: </td>
<td>
<select name="price">
<option value=">= 0">- Any Price -</option>
<option value="<= 15">< 15</option>
<option value="<= 25">< 25</option>
<option value="<= 50">< 50</option>
<option value=">= 50">> 50</option>
</select></td>
</tr>
<tr>
<td colspan="2" style="padding-left:41">
<select name="category">
<option value="">- Any Category -</option>
<?php
$sql = mysql_query("SELECT * FROM categories ORDER BY templates ASC");
while ($row = mysql_fetch_array($sql)) {
echo "<option value='".$row['templates']."'>".$row['templates']."</option>";
}
?>
</select></td>
</tr>
<tr>
<td align="center" style="padding-left:40" colspan="2"><input type="image" src="/images/search_but.jpg" border="0" width="68" height="24" style="border: thin solid #ffffff;"></td>
</tr></form>
---------------------------------------------------------------------------------
search.php
---------------------------------------------------------------------------------
Code: Select all
$result = mysql_query("SELECT * FROM templates WHERE
author='".$_POST['$author']."' OR id='".$_POST['$itemid']."' OR
category='".$_POST['$category']."' AND price ".$_POST['$price']." LIMIT
".(($current - 1) * $count).", " . $count);
---------------------------------------------------------------------------------
i get no errors, it just displays the wrong results, or doesnt show anything sometimes, but when i play with the code, it kind of works, lol
Posted: Tue Nov 16, 2004 5:41 pm
by timvw
Posted: Tue Nov 16, 2004 5:51 pm
by ecaandrew
where do i put that line?
Posted: Tue Nov 16, 2004 5:52 pm
by timvw
at the beginning....
Posted: Wed Nov 17, 2004 4:21 am
by ecaandrew
here are my results.
2039
There are no templates in the database.
Pages: 1