Re: Can't do anything with variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux