Page 1 of 1
Print "You didn't enter a Search term" or somethin
Posted: Sat Apr 22, 2006 8:06 pm
by Maluendaster
This is the Code, the problem is when someone doesn't enter a search text, it shows an error, what i want is when someone didn't enter a search term that the page print something like "You didn't enter a search term" :
Code: Select all
<?include("header.php");?>
<?
$query = $_GET['query'];
$tim = file("prodtable.db");
$sizecat = count($tim);
////////////////////////////////////
for($i=-1;$i<$sizecat;$i++){
$deti = explode("#",$tim[$i]);
if(stristr($deti[2],$query)){
echo "<table border='0' align='center' cellpadding='2' cellspacing='2'><tr><td bgcolor='#EEEEEE'><IMG SRC='prodimg/$deti[5]'> <BR><B>Nombre:</B> $deti[2] <BR><B>Precio:</B> $deti[3]$curency<BR> <a href='prodshow.php?id=$i'><b style='color:#000000; background-color:#AAAAAA'>[ detalles ]</b></a> </td><td bgcolor='#EEEEEE' width='100%'><B>About:</B> $deti[4] </td></tr></table>";
}
}
?>
</TD>
</TR>
</TABLE>
<? include("footer.php"); ?>
THANK YOU
Posted: Sat Apr 22, 2006 8:16 pm
by John Cartwright
Code: Select all
$query = $_GET['query'];
if (empty($query)) {
echo 'Enter search term';
}
else {
// do everything else
}
empty(), you might want to validate the string if your inputting $query directly into the query. Search for SQL injection.
Posted: Sun Apr 23, 2006 7:41 am
by Chris Corbyn
Code: Select all
if (isset($_GET['query']) && empty($_GET['query'])) {
echo 'Enter search term';
}
else {
// do everything else
}
This is where you need to figure out if they actually have even submitted the form with no data or they haven't submitted it at all. I'd use a combination of isset() and empty().
Posted: Sun Apr 23, 2006 10:45 am
by John Cartwright
d11wtq wrote:Code: Select all
if (isset($_GET['query']) && empty($_GET['query'])) {
echo 'Enter search term';
}
else {
// do everything else
}
This is where you need to figure out if they actually have even submitted the form with no data or they haven't submitted it at all. I'd use a combination of isset() and empty().
That's pointless because
empty() checks for the existence of the variables just as
isset() does, except it checks to make sure the variable is not empty as well.
Posted: Sun Apr 23, 2006 11:06 am
by Chris Corbyn
Jcart wrote:d11wtq wrote:Code: Select all
if (isset($_GET['query']) && empty($_GET['query'])) {
echo 'Enter search term';
}
else {
// do everything else
}
This is where you need to figure out if they actually have even submitted the form with no data or they haven't submitted it at all. I'd use a combination of isset() and empty().
That's pointless because
empty() checks for the existence of the variables just as
isset() does, except it checks to make sure the variable is not empty as well.
Yes, think about it
You open google.com for the first time. Now if it told you that you haven't entered a search query would that seem confusing? If you then proceeded to hit submit without entering any text and it said you've not entered a query qould it make sense?
The isset() checks that the user actually submitted the form, then the empty() checks if any data was sent by the user. Just using empty() doesn't allow you that knowledge since empty() matches:
array()
''
false
0
null
(unset)

Posted: Sun Apr 23, 2006 11:19 am
by John Cartwright
Yup your right, I'm used to using post and checking $_SERVER['REQUEST_METHOD'] .. stumped me on that one..

Posted: Sun Apr 23, 2006 12:55 pm
by Maluendaster
thank you for everything! it worked both ways, but I used isset too...