Forum Moderators: coopster

Message Too Old, No Replies

Nasty undefined index messages

         

Shaman13

6:19 pm on Dec 22, 2004 (gmt 0)

10+ Year Member



Can anyone tell me why the unsightly Undefined index messages keep popping up on some of my forms? So far I have tweaked error reporting in the Php.ini without success. The messages disappear after the form is submitted. Do I have to give these indexes some default value in the form so they don't appear prior to submit.

These messages do not appear on my developement machine which is a Windows 2000 box but they appear on my Linux machine.

Any and all suggestions are greatly appreciated!

Notice: Undefined index: TIDATE in /var/www/html/my_time.php on line 46

jatar_k

6:30 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would bet that initializing them would work.

what is the code on line 46?

coopster

6:30 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Because you have errors in your code ;) See the PHP error_reporting() [php.net] function pages to get you started.

Shaman13

6:36 pm on Dec 22, 2004 (gmt 0)

10+ Year Member



Thanks for the assist!

Here is the accompanying code. The problem seems to start when I declare the variables. I thought I might be able to fix it by adding code to check to see if the form has been submitted yet. Unfortunately, I am still pretty green at this stuff and don't fully understand how to do that.

<?php

// create short variable names

$TIDATE=$HTTP_POST_VARS['TIDATE'];
$TIDATEA=$HTTP_POST_VARS['TIDATEA'];
$TIDATEB=$HTTP_POST_VARS['TIDATEB'];

$TIDATEA= trim($TIDATEA);
$TIDATEB= trim($TIDATEB);

if (!$TIDATE ¦¦!$TIDATEA)
{
echo 'You have not entered search details. Please go back and try again.';
exit;
}

$TIDATE = addslashes($TIDATE);
$TIDATEA = addslashes($TIDATEA);
$TIDATEB = addslashes($TIDATEB);
$result = mysql_query( "SELECT *,SUM(TTIME) FROM ttime left join _clientsw_cases ON ttime.CASENUM=_clientsw_cases.CASENUM WHERE ttime.SNUM = '".$_SESSION['SNUM']."' AND (TIDATE BETWEEN '%".$TIDATEA."%' AND '%".$TIDATEB."%') GROUP BY TIDATE ")

//01$result = mysql_query( "SELECT *,SUM(TTIME) FROM ttime left join _clientsw_cases ON ttime.CASENUM=_clientsw_cases.CASENUM WHERE ttime.SNUM = '".$_SESSION['SNUM']."' AND (TIDATE BETWEEN '%".$TIDATEA."%' AND '%".$TIDATEB."%') GROUP BY TIDATE ")

//o$result = mysql_query( "SELECT TIDATE,SNUM,FUNDSNUM,REASON,CASEACTIVITY,TIMEACTIVITY,NONCASE,CASENUM,TIMEID,TTIME,SUM(TTIME) FROM ttime WHERE SNUM = '".$_SESSION['SNUM']."' AND (TIDATE BETWEEN '%".$TIDATEA."%' AND '%".$TIDATEB."%') GROUP BY TIDATE ")
//$result = mysql_query( "SELECT * FROM ttime WHERE SNUM = '".$_SESSION['SNUM']."' AND (TIDATE LIKE '%".$TIDATEA."%' OR TIDATE LIKE '%".$TIDATEB."%')")
//$result = mysql_query( "SELECT * FROM ttime where (SNUM = '".$_SESSION['SNUM']."') and (TIDATE = '%".$TIDATEA."%' OR '%".$TIDATEB."%')")
//$result = mysql_query( "SELECT * FROM ttime where (SNUM = '".$_SESSION['SNUM']."') and (TIDATE >= '%".$TIDATEA."%') OR (TIDATE <= '%".$TIDATEB."%')")

//$result = mysql_query( "SELECT * FROM ttime where ((SNUM = '".$_SESSION['SNUM']."') and ".$TIDATE." LIKE'%".$TIDATEA."%' ) or ((SNUM = '".$_SESSION['SNUM']."') and ".$TIDATE." LIKE '%".$TIDATEB."%') ORDER BY TIDATE ASC")
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
//print "You currently have $num_rows time entries for "

?>

<font color="#FF0000"size="3">
</b>
</font>

<font face="Times New Roman" size="3">
<blockquote>
<b>Time Spent By Day</B>
<?php
print("<TABLE BORDER=1,width=725,body bgcolor=#FFFFFF><TR>");
print("<TH>Date</TH>");
print("<TH>Total</TH>");

for ($index = 0; $index < 5; $index++)

while($row=mysql_fetch_array($result)) {

print '<tr><td>'.$row['TIDATE'].'</td><td>Total '.$row['SUM(TTIME)'].'</td></tr>';
}

?>
<table></table>

jatar_k

6:38 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



and which is line 46? the end?

Shaman13

6:43 pm on Dec 22, 2004 (gmt 0)

10+ Year Member



The line which throws the error is the first one

$TIDATE=$HTTP_POST_VARS['TIDATE'];

coopster

6:51 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



A good practice to get into would be to make sure your POSTed variables do indeed exist first. And if they don't, give them a default value.
$TIDATE= (isset [php.net]($HTTP_POST_VARS['TIDATE'])) ? $HTTP_POST_VARS['TIDATE'] : '';
Also, are you sure you want to be using HTTP_POST_VARS rather than the more modern $_POST superglobal [php.net]? ;)

Shaman13

6:58 pm on Dec 22, 2004 (gmt 0)

10+ Year Member



Thanks you guys! That works fine. Coopster is there an advantage to using the newer syntax. Thanks a lot for your help again!

coopster

7:06 pm on Dec 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Click the "superglobals" link and read the first few paragraphs (reading the whole thing only takes a few minutes).

The $HTTP_*_VARS contain the same initial information but are not autoglobals. Plus, with PHP5 they can be turned off completely, a good sign it may be deprecated in the future.