Page 1 of 1

PHP Notice : Undefined variable & index

Posted: Tue May 08, 2007 5:10 am
by bouncer
i'm getting this notices ...

Code: Select all

PHP Notice:  Undefined variable: cet ...
PHP Notice:  Undefined variable: referer ...

Code: Select all

if ($cet) {
	$usacetelem=1;
	session_register("usacetelem");
}

if (strlen($referer) == 0) {
	if (strlen(strstr($HTTP_REFERER,'loja')) > 0) { $referer = "http://".$HTTP_HOST; }
	else { $referer = $HTTP_REFERER; }
	session_register("referer");
}
else {
	if (strlen(strstr($HTTP_REFERER,'loja')) == 0) { $referer = $HTTP_REFERER; }
	session_register("referer");
}
why i'm getting this notices, and how i can eliminate them ?

thanks in advance

Posted: Tue May 08, 2007 5:17 am
by dhrosti
You have to "create" the variable before you can use it.

At the top of your script, before any data is passed to them...

Code: Select all

var $cet;
var $referer;

Posted: Tue May 08, 2007 5:49 am
by bouncer
dhrosti wrote:You have to "create" the variable before you can use it.

At the top of your script, before any data is passed to them...

Code: Select all

var $cet;
var $referer;
i've add those line to my code, and now i'm getting this ...

Code: Select all

PHP Parse error:  syntax error, unexpected T_VAR ...

Posted: Tue May 08, 2007 6:12 am
by Grim...
Can you post your code again, and the entire error message?

Posted: Tue May 08, 2007 6:49 am
by bouncer

Code: Select all

<?
session_start();
require "../lib/config.obj.php";
require "$dir_site/lib/globalserver.obj.php";
require "loja.obj.php";

if ( $cet ) { 
	$usacetelem = 1;
	session_register ( "usacetelem" );
}

if ( strlen ( $referer ) == 0 ) {
	if ( strlen ( strstr ( $HTTP_REFERER, 'loja' ) ) > 0 ) { $referer = "http://".$HTTP_HOST; }
	else { $referer = $HTTP_REFERER; }
	session_register ( "referer" );
}
else {
	if ( strlen ( strstr ( $HTTP_REFERER, 'loja' ) ) == 0 ) { $referer = $HTTP_REFERER; }
	session_register ( "referer" );
}

$wOperacao = $action;
$wIdConfigurador = $idConfigurador;
$wCodproduto = $prod;
$wQuantidade = $qtd;

if ( !$preco ) {
	$wPreco = 0;
}
else {
	$wPreco = $preco;
}
$wTotal = $total;

if( $wOperacao ) {
	$ceq = 1;
}
else {
	$ceq = 0;
}

if ( !$opcionais )  {
	for ( $x = 0; $x < sizeof ( $opcional ); $x++ ) {
		if ( $opcional[$x] != "-" and strlen ( $opcional[$x] ) > 0 ) $wOpcionais .= $opcional[$x]."**";
	}

	$wOpcionais = substr ( $wOpcionais, 0, strlen ( $wOpcionais ) - 2 );
}
else {
	$wOpcionais = $opcionais;
}

Code: Select all

PHP Notice:  Undefined variable: cet in /var/www/html/loja/comprar.php on line 8
PHP Notice:  Undefined variable: action in /var/www/html/loja/comprar.php on line 25
PHP Notice:  Undefined variable: idConfigurador in /var/www/htmlloja/comprar.php on line 26
PHP Notice:  Undefined variable: total in /var/www/html/loja/comprar.php on line 35
PHP Notice:  Undefined variable: opcionais in /var/www/html/loja/comprar.php on line 44
PHP Notice:  Undefined variable: opcional in /var/www/html/loja/comprar.php on line 45
PHP Notice:  Undefined variable: wOpcionais in /var/www/html/loja/comprar.php on line 49
this appears after i change from php 4 to php 5.1 ...

Posted: Tue May 08, 2007 6:51 am
by superdezign
Here's the problem. You're checking the values of $cet and $referrer before they have any values at all. Where are you setting their values?

Posted: Tue May 08, 2007 9:38 am
by feyd
superdezign wrote:Here's the problem. You're checking the values of $cet and $referrer before they have any values at all. Where are you setting their values?
Judging from the code, bouncer is assuming register globals is on and they are therefore set for him at page submission.

Posted: Tue May 08, 2007 11:29 am
by bouncer
feyd wrote:
superdezign wrote:Here's the problem. You're checking the values of $cet and $referrer before they have any values at all. Where are you setting their values?
Judging from the code, bouncer is assuming register globals is on and they are therefore set for him at page submission.
you are right, i have register globals on, but i have already try something like this

Code: Select all

if ( isset ( $cet ) ) { ... }
without any progress :cry:

i know that i can hide this notices by editing php.ini, but i dont get any kind of error ... :?

the code isnt supose to work with PHP Notices ?
how can i get ride of this notices ?

thanks in advance

Posted: Tue May 08, 2007 4:09 pm
by RobertGonzalez
You need to set $cet equal to something before calling it.

Code: Select all

<?php
$cet = false;

if (isset($_POST['cet']))
{
  $cet = $_POST['cet'];
}

if ($cet)
{
  //...
}
?>
Don't settle for shutting the error up when you can actually make your code error free.

Posted: Wed May 09, 2007 9:38 am
by bouncer
thanks :wink: