PHP Variables

J

Jason2k1

Guest
#1
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
 
#2
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.
}
 

Khayman

I'm sorry Hal...
Political User
#3
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 posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,971
Messages
673,299
Members
89,016
Latest member
Poseeut