PHP Variables

J

Jason2k1

Guest
I use php variables passed from page to page by the query string at the end of the url. does anyone know of the code that will declare a default value to a variable if one is not present in the query string?

Thanks in Advance

Jason
 
The default value will be 0, "" or false depending on use. Using non-existant variables in PHP is not a problem.

The only thing might be if PHP is set to print out notices. Make sure the error reporting line in php.ini looks like:
error_reporting = E_ALL & ~E_NOTICE

Or you could do:
PHP:
if(!isset($varname)){
     $varname = 0      // Or whatever you want to initialize with.
}
 
Can also do somethin like

PHP:
$var= $_GET["urlstring"];
if (isset($var) ==0) /*i.e. if no value in $var*/
{
	$var= 1; /*then set it to 1 (or whatever default)*/
}
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,623
Latest member
AndersonLo
Back