Re: Can't do anything with variables
| From: | Ronan Chilvers | Date: | Mon, 07 Apr 2003 09:58:14 +0000 |
| Subject: | Re: Can't do anything with variables | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-26888@lists.php.net to get a copy of this message | ||
Hi Gilles
Comments inline...
On 06 Apr,2003 at 21:17 Gilles Gilles wrote:
<snip>
> Sorry for this really beginner question (PHP-Newbie here). I bought the book "PHP and
> MySQL web developpement" (Welling & Thompson)
</snip>
Pretty good book, have it myself. Worth a read. Also Coriolis' PHP Black Book is worth a go.
<snip>
> <h1>Book-O-Rama Search Results</h1>
> <?
> if (!$searchtype || !$searchterm)
> {
> echo "You have not entered search details. Please go back and try again.";
> exit;
> }
>
</snip>
<snip>
> The problem. Even if I fill both fields, I always get "Notice: Undefined variable:
> searchtype"
>
</snip>
My guess is that you are using a windows platform ? The windows version of PHP doesn't like
variable testing syntax like:-
if ($testvar) { echo "hallo"; } // You can get away with this on *nix.
It insists that you use:-
if (isset($testvar)) { echo "hallo"; }
So, the script should read...
if ((!isset($searchtype)) || (!isset($searchterm)))
{
echo "You have not entered search details. Please go back and try again.";
exit;
}
It's good practice to use isset() rather than a direct test, anyway. Keeps your scripting
readable and safe.
BTW, it isn't a great idea to turn off error reporting as others advocate ... error messages
are there because something is wrong ... I reckon you should fix the problem, not hide the error.
Cheers
--
Ronan
e: ronan@thelittledot.com
t: 01903 739 997
w: www.thelittledot.com
The Little Dot is a partnership of
Ronan Chilvers and Giles Webberley