Connecting Tech Pros Worldwide Help | Site Map

Help please: just a simple search..

ZafT
Guest
 
Posts: n/a
#1: Aug 11 '06
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>";
}

}
?>

****************************************


Tomasz Rup
Guest
 
Posts: n/a
#2: Aug 11 '06

re: Help please: just a simple search..


ZafT napisal(a):
Quote:
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

Andy
Guest
 
Posts: n/a
#3: Aug 11 '06

re: Help please: just a simple search..


snip
Quote:
>
<?php
>
if(!(isset($search))){
$query="SELECT * FROM item ORDER BY name DESC";
if(!(isset($count))){

Put

$searh = $_POST['search'];

just after the <?php


ZafT
Guest
 
Posts: n/a
#4: Aug 11 '06

re: Help please: just a simple search..


Quote:
Put
>
$search = $_POST['search'];
>
just after the <?php
That did it - Thanks!

Shane


Closed Thread