Page 1 of 1

Variables! Notice: Undefined index:

Posted: Wed May 11, 2005 12:18 am
by facets
Hey Gang,

Could some one point me in the right direction.
I thought I was setting the variables with the $_GET lines below.

Cheers, Will

Code: Select all

<?

include "../includes/functions.inc";
include "../includes/common_db.inc";

$link_id = db_connect($db_materials);

// Set global variables to easier names
$description = $_GET['description'];
$basisWeight = $_GET['basisWeight'];

$sql_add = "INSERT INTO austock values('','$description','$basisWeight','','','','','','','','','','','','','','','','','','')";

mysql_query($sql_add) or die(mysql_error());

?>

<form method='get' action='<?php echo $_SERVER['PHP_SELF']; ?>'>

<table class=\"sample\"><tr>
<td width=200px colspan=2 valign=top >Description</td>
<td width=200px colspan=3><input type='text' name='description' SIZE="20"></td></tr>

<tr><td width=200px colspan=2 valign=top>Basis Weight</td>
<td width=200px colspan=3><input type='text' name='basisWeight' SIZE="20"></td></tr>

<tr><td width=200px colspan=2 valign=top>Caliper</td>
<td width=200px colspan=3><input type='text' name='caliper' SIZE="20"></td></tr>

<tr><td width=200px colspan=2 valign=top>Wet Tensile Strength CD</td>
<td width=50px colspan=2><input type='text' name='wetTensileStrenghtCD' value="<?php echo $wetTensileStrenghtCD ?>" SIZE="20"></td></tr>

<tr><td width=200px colspan=2 valign=top>Dry Tensile Strength CD</td>
<td width=50px colspan=2><input type='text' name='wetTensileStrenghtMD' value="<?php echo $wetTensileStrenghtMD ?>" SIZE="20"></td</tr>

<tr><td width=100px colspan=2 valign=top><input type='reset' class='btn' value='Reset Face Stock'></td>
<td width=100px colspan=3><input type='submit' name='addFs' class='btn' value='Add Face Stock'></td></tr>


</form>
<?
?>

Posted: Wed May 11, 2005 12:25 am
by andre_c
what's the exact error?

Posted: Wed May 11, 2005 12:26 am
by MaxBlast-PHP
First of are you getting any errors?
second of all why do you have at the end

Code: Select all

<?
 ?>
that might be your problem try something like

Code: Select all

<? 
}
?>

Posted: Wed May 11, 2005 12:48 am
by facets
Sorry guys..

Code: Select all

Notice: Undefined index: description in c:\program files\easyphp1-8\www\materialsregister\newtest.php on line 16

Notice: Undefined index: basisWeight in c:\program files\easyphp1-8\www\materialsregister\newtest.php on line 17

Posted: Wed May 11, 2005 1:12 am
by php_wiz_kid
What is your error_reporting set to in your php.ini? It might be that it's set to E_ALL and in that case you need to check if your global variables (_GET, _POST, etc...) exist using isset. If they don't exist it'll error out giving you an undefined index warning. Here's what I do:

Code: Select all

function set_make_null(&$global) {
  if(!isset($global)) {
    $global = "";
  }
}
Pass the global variables that are erroring out into the function and see if that helps at all.

Posted: Wed May 11, 2005 1:16 am
by facets
Sure..
I guess what i'm asking is what is the correct way (read 'standards') of handling globals with globals=off and reporting E_ALL

Obviously I can add the following to remove the notices.
//error_reporting(E_ALL & ~E_NOTICE).

Cheers!

Posted: Wed May 11, 2005 1:17 am
by php_wiz_kid
I run PHP with E_ALL and after I asked around a while back the "pro's" told me that setting the global to empty or null is the best, most secure practice. That's just what I've enquired throught his forum.

Posted: Wed May 11, 2005 1:43 am
by facets
If I add

Code: Select all

if(isset($_GET['commented']))
{
echo('Your comment has been posted.');
include "../includes/functions.inc";
include "../includes/common_db.inc";
and

Code: Select all

}
    else {
?>
<form method='get' action='<?php echo $_SERVER['PHP_SELF']; ?>'>
<input type='hidden' name=commented value='set'>
The notice's disappear but I don't know why.

Can anyone fill me in?

tia..

Posted: Wed May 11, 2005 3:25 am
by phpScott
the isset() function checks to see if a variable is set, hence the name, does the variable exists. if your case if the variable comment isset then do your echo for comment has been submitted. if comment hasn't been set (in other words doesn't exist)then it will echo your html code.