search query

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!

Moderator: General Moderators

Post Reply
ecaandrew
Forum Commoner
Posts: 72
Joined: Fri Nov 12, 2004 5:05 pm

search query

Post 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 :)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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)
nashhill
Forum Newbie
Posts: 1
Joined: Tue Nov 16, 2004 4:35 am
Location: china

test it like this

Post by nashhill »

you should test it on PhpMyAdmin
or some soft for use in mysql


That you will get the answer quickly!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
ecaandrew
Forum Commoner
Posts: 72
Joined: Fri Nov 12, 2004 5:05 pm

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Code: Select all

error_reporting(E_ALL);
ecaandrew
Forum Commoner
Posts: 72
Joined: Fri Nov 12, 2004 5:05 pm

Post by ecaandrew »

where do i put that line?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

at the beginning....
ecaandrew
Forum Commoner
Posts: 72
Joined: Fri Nov 12, 2004 5:05 pm

Post by ecaandrew »

here are my results.

2039
There are no templates in the database.
Pages: 1
Post Reply