Page 1 of 1

to do with Notice error??

Posted: Sat May 21, 2005 7:36 am
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

Posted: Sat May 21, 2005 8:18 am
by timvw
you can use one of the following functions:

isset
empty
array_key_exists

Posted: Sat May 21, 2005 11:09 am
by paolo
thanks a lot timvw!

Posted: Sun May 22, 2005 4:44 am
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

Posted: Sun May 22, 2005 6:54 am
by timvw
That is because $_SESSION['ragsociale1'] doesn't exist.

Code: Select all

$ragsociale1 = isset($_SESSION['ragsociale1']) ? $_SESSION['ragsociale1'] : 'default';

Posted: Sun May 22, 2005 11:29 am
by cg111
IF YOU WANT USE SESSION ,IN FIRST YOU MUST WRITE "Session_Start();" IN THE FIRST LINE,PLEASE CHECKED IT.

Posted: Sun May 22, 2005 11:32 am
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.

Posted: Sun May 22, 2005 12:10 pm
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.

Posted: Sun May 22, 2005 3:20 pm
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.