CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Resolved "Use of undefined constant" and $_POST['aaa'] (http://www.codingforums.com/showthread.php?t=283973)

fail 12-11-2012 01:54 PM

"Use of undefined constant" and $_POST['aaa']
 
I wanted to update the company server from XAMPP 1.73 to 1.81 today, but thought, well, just do it at home first. And bongo, nothing works!

PHP Code:

// Sample #1:

// Notice: Use of undefined constant date - assumed 'date' in C:\xampp\htdocs\bom3\scams\rthk.php on line 49

$date = ($_POST['date']);

// Sample #2:

//Notice: Undefined index: flg in C:\xampp\htdocs\bom3\scams\tool.php on line 23
//Notice: Undefined index: flg in C:\xampp\htdocs\bom3\scams\tool.php on line 24

if($_POST['flg'] == 'ugg' ) {$bbb 'selected';} ELSE {$bbb '';}
if(
$_POST['flg'] == 'uggi' ) {$bbbi 'selected';} ELSE {$bbbi '';} 

I get the message when I land on the page and the forms aren't filled.

I think it may be related to isset, or the lack of it. Hope to get some hints here.

Redcoder 12-11-2012 02:27 PM

You might as well as have an IF check because the $date is probably messing things up in some code somewhere else which is still being executed whether $_POST['date'] has anything or not.

Fou-Lu 12-11-2012 02:52 PM

This will not throw an undefined constant notice:
PHP Code:

// Sample #1:

// Notice: Use of undefined constant date - assumed 'date' in C:\xampp\htdocs\bom3\scams\rthk.php on line 49

$date = ($_POST['date']); 

'date' has been properly identified as a string. Look elsewhere for this error for which you want to find the (undefined) constant date in use.

PHP Code:

// Sample #2:

//Notice: Undefined index: flg in C:\xampp\htdocs\bom3\scams\tool.php on line 23
//Notice: Undefined index: flg in C:\xampp\htdocs\bom3\scams\tool.php on line 24

if($_POST['flg'] == 'ugg' ) {$bbb 'selected';} ELSE {$bbb '';}
if(
$_POST['flg'] == 'uggi' ) {$bbbi 'selected';} ELSE {$bbbi '';} 

This one simply has no offset under the name 'flg'. Check it with isset before attempting to read it.

Given the names in your filepaths here and the comparison criteria there, I'll sure raise question to future help requests.

fail 12-12-2012 02:59 AM

Quote:

Originally Posted by Fou-Lu (Post 1299077)
Given the names in your filepaths here and the comparison criteria there, I'll sure raise question to future help requests.

..it's a little tool for tracking scam stores that I use for some time. Nothing sinister. Just the move to the latest XAMPP messed things a little up.

Now time to learn more about 'isset'.....

fail 12-12-2012 03:01 AM

Quote:

Originally Posted by Redcoder (Post 1299071)
You might as well as have an IF check because the $date is probably messing things up in some code somewhere else which is still being executed whether $_POST['date'] has anything or not.

I presume the problem is that the date ain't set in the form when it first opens. Hence, blank forms seem to cause trouble in the latest XAMPP (or at least with a fresh installed XAMPP).

fail 12-15-2012 04:36 AM

Solved the problem by using isset for each error at the beginning of the page:

PHP Code:

if (!isset($_POST['rthk']))   {    $_POST['rthk'] = ""; } 

Another way is to change error_reporting = in xampp\php\php.ini

But maybe a better way is to leave it in php.ini at the default error_reporting = E_ALL | E_STRICT and and use on your page i.e. error_reporting("E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR");

I am aware that it's better to have all errors reported and just write better code.


All times are GMT +1. The time now is 05:22 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.