By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,994 Members | 1,570 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,994 IT Pros & Developers. It's quick & easy.

Help please: just a simple search..

P: n/a
Thanks for any help in advance. I am using this exact same piece of code on
a server running PHP4, but for some reason when I run it on dreamhost using
PHP5, the search does not register and it just lists all items. There's not
much code, so I'm just putting it all in here. The script calls itself.
Can someone please tell me why the
if(!(isset($search)))
is ignored when the form is posted?

Thanks,

Shane
********************************

Search:<form method="post" action="listitem.php">
<input type="text" name="search">
<input type="hidden" name="count" value="20">
<input type="submit" value="search">
</form><BR>
<?php

if(!(isset($search))){
$query="SELECT * FROM item ORDER BY name DESC";
if(!(isset($count))){
$count=20;
}
}

else{
$query="SELECT * FROM item WHERE name LIKE '%$search%' OR description
LIKE '%$search%' ORDER BY name DESC";

if(!(isset($count))){
$count=20;
}
}
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
$bottom = ($count - 20);
while (($i < $count) && ($i < $num)) {

if ($i < $bottom){
$i++;
}

else{

$name=mysql_result($result,$i,"name");
$location=mysql_result($result,$i,"location");

echo "<LI><A HREF=$location>$name</A>";
echo "</LI<BR><BR>";
$i++;
}
}
if ($count < $num){

$count = ($count + 20);

if(!(isset($search))){
echo "<A HREF=/listitem.php?count=$count>Next 20</A>";
}
else{
echo "<A HREF=/listitem.php?count=$count&search=$search>Next 20</A>";
}

}
?>

****************************************
Aug 11 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ZafT napisal(a):
Can someone please tell me why the
if(!(isset($search)))
is ignored when the form is posted?
Read about register_globals directive. In php4 default is on, in php5 -
off.

--
Tomasz Rup

Aug 11 '06 #2

P: n/a
snip
>
<?php

if(!(isset($search))){
$query="SELECT * FROM item ORDER BY name DESC";
if(!(isset($count))){

Put

$searh = $_POST['search'];

just after the <?php
Aug 11 '06 #3

P: n/a
Put

$search = $_POST['search'];

just after the <?php
That did it - Thanks!

Shane
Aug 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.