to do with Notice error??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paolo
Forum Newbie
Posts: 15
Joined: Sat May 14, 2005 6:06 am

to do with Notice error??

Post by paolo »

Hello,
I've just searched the forum and googled to find a solution for those errors:

Notice: Undefined index: go_back in c:\wwwroot\frigerio\anagrafica_ins0.php on line 119

Notice: Undefined variable: ragsociale1 in c:\wwwroot\frigerio\anagrafica_ins0.php on line 155
....
I've got all of them for the following piece of code

Code: Select all

$ragsociale1 = $_SESSION['ragsociale1'];
		$ragsociale2 = $_SESSION['ragsociale2'];
		$indirizzo = $_SESSION['indirizzo'];
		$cap = $_SESSION['cap'];
		$citta = $_SESSION['citta'];
		$provincia = $_SESSION['provincia'];
		$modauto = $_SESSION['modauto'];
		$targaauto = $_SESSION['targaauto'];
		$garanzia = $_SESSION['garanzia'];
		$circolare = $_SESSION['circolare'];
		$telefono = $_SESSION['telefono'];
		$cellulare = $_SESSION['cellulare'];
		$email = $_SESSION['email'];
		$kmanno = $_SESSION['kmanno'];
		$dtnextcirc = $_SESSION['dtnextcirc'];
		$dtproxctrl = $_SESSION['dtproxctrl'];
		$servizioneve = $_SESSION['servizioneve'];
		$qtgommeneve = $_SESSION['qtgommeneve'];
		$stampa_garanzia = $_SESSION['stampa_garanzia'];
		$stampa_circolare = $_SESSION['stampa_circolare'];
		$sede = $_SESSION['sede'];

I've tried also to put a @ before $variable_name but it doesn't solve the problem.. I know this happens since first time I visit the page I don't have variables stored into session's variables space, but the first time it's right, any suggestion to fix it? I can't change error level reporting.
Thanks
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

you can use one of the following functions:

isset
empty
array_key_exists
paolo
Forum Newbie
Posts: 15
Joined: Sat May 14, 2005 6:06 am

Post by paolo »

thanks a lot timvw!
paolo
Forum Newbie
Posts: 15
Joined: Sat May 14, 2005 6:06 am

Post by paolo »

excuse me again, I recevive those message error
Notice: Undefined variable: ragsociale1 in c:\wwwroot\frigerio\anagrafica_ins0.php on line 154

Notice: Undefined variable: ragsociale2 in c:\wwwroot\frigerio\anagrafica_ins0.php on line 156

Notice: Undefined variable: indirizzo in c:\wwwroot\frigerio\anagrafica_ins0.php on line 160
here

Code: Select all

<form name=\"p\" method=\"post\"  action=\"anagrafica_ins1.php\"   onsubmit=\"return CheckValidation(this);\">
	<table cellspacing=\"2\" cellpadding=\"5\" width=\"50%\" border=\"1\" align=\"center\" name=\"table\">
		<tr>
			<th align=\"center\" width=\"52\">Rag. Sociale 1*</th>
			<td width=\"50%\"><input type=\"text\" size=\"30\" name=\"ragsociale1\" value=\"$ragsociale1\"></td>
			<th align=\"center\" width=\"52\">Rag. Sociale 2</th>
			<td width=\"180\"><input size=\"30\" name=\"ragsociale2\" value=\"$ragsociale2\"></td>
		</tr>
		<tr >
			<th width=\"20%\">Indirizzo*</th>
			<td width=\"50%\"><input size=\"30\" name=\"indirizzo\" value=\"$indirizzo\"></td>
			<th width=\"20%\">Città*</th>
			<td width=\"50%\"><input size=\"30\" name=\"citta\" value=\"$citta\"></td>
		</tr>
		<tr >
even if I do up in the code

Code: Select all

if(!isset($ragsociale1)) $ragsociale1= $_SESSION['ragsociale1'];
how do I fix it??
Thanks again
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

That is because $_SESSION['ragsociale1'] doesn't exist.

Code: Select all

$ragsociale1 = isset($_SESSION['ragsociale1']) ? $_SESSION['ragsociale1'] : 'default';
cg111
Forum Newbie
Posts: 4
Joined: Sun May 22, 2005 8:49 am
Location: China

Post by cg111 »

IF YOU WANT USE SESSION ,IN FIRST YOU MUST WRITE "Session_Start();" IN THE FIRST LINE,PLEASE CHECKED IT.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

cg111 wrote:IF YOU WANT USE SESSION ,IN FIRST YOU MUST WRITE "Session_Start();" IN THE FIRST LINE,PLEASE CHECKED IT.
uh.. please do not write in caps.
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

If he would not use session_start() he would not get a notice but a fatal error.


A notice only shoes up on error reporting all in php.ini. If you use a variable without initializing it first you get the notice. If you session variable does not exist it does not count as initialization. You could use a $var = ""; for every var first to avoid the notice. Sometimes it can be a pain to honor all notices.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

But, it's a good idea. Undefined variables/indexes are always some of the biggest problems when it comes to this, but they make poisoning scripts with register globals far easier.
Post Reply