Hi folks

I've just moved my site and databases into easyphp WAMP (first time I've ever used it).
I got everything in but I'm seeing errors in the local site I don't get (or are hidden) on the live site.

For example I'm getting this error:

Notice: Undefined index: email in C:\web\gbpc\login.php on line 6

from this code:

<?php
/* 
Created By Adam Khoury @ www.flashbuilding.com 
-----------------------June 20, 2008----------------------- 
*/
if ($_POST['email']) {
//Connect to the database through our include 
include_once "connect_to_mysql.php";
$email = stripslashes($_POST['email']);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters
$password = md5($password);
// Make query and then register all database data that -
// cannot be changed by member into SESSION variables.
// Data that you want member to be able to change -
// should never be set into a SESSION variable.
$sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$password' AND emailactivated='1'"); 
$login_check = mysql_num_rows($sql);

I also have this error appearing on lines 107,108,109 & 110:

Notice: Undefined variable: bonusGROUPED in C:\web\gbpc\includes\finalists.php on line 107
Notice: Undefined variable: pointsGROUPED in C:\web\gbpc\includes\finalists.php on line 108
Notice: Undefined variable: totalpointsGROUPED in C:\web\gbpc\includes\finalists.php on line 109
Notice: Undefined variable: playedGROUPED in C:\web\gbpc\includes\finalists.php on line 110

from this section of code:

foreach ($arr as $key => $row) { 										// THIS SECOND LOOP BUILD AN ARRAY FOR EACH PRSON AT EACH VENUE
																		// ADDING THE POINTS FOR EACH VENUE AND ADDING THE NUMBER OF TIMES
																		// PLAYED AT EACH VENUE. BEAUTY

$bonusGROUPED[$row[1].$row[2].$row[3]] = $bonusGROUPED[$row[1].$row[2].$row[3]] + $row[4] + $row[5]; //grouped data with bonus chips
$pointsGROUPED[$row[1].$row[2].$row[3]] = $pointsGROUPED[$row[1].$row[2].$row[3]] + $row[6]; //creates grouped data for each player with points
$totalpointsGROUPED[$row[1].$row[2].$row[3]] = $totalpointsGROUPED[$row[1].$row[2].$row[3]] + $row[4] + $row[5] + $row[6];//creates grouped data for each player with points
$playedGROUPED[$row[1].$row[2].$row[3]] = $playedGROUPED[$row[1].$row[2].$row[3]] +1; //creates grouped data for number of times played
$GBPCPoints = $totalpoints33GROUPED[$row[1].$row[2].$row[3]] * $average_by_venue[$row[3]] / 20; // calculates number of chips
$CHIPS = ceil($GBPCPoints / 25) * 25; //rounds up chipstack to nearest 25		

$arrGROUPED[$row[1].$row[2].$row[3]] =  array(1 => $row[1], 2 => $row[2], 3 => $row[3], 4 => $bonusGROUPED[$row[1].$row[2].$row[3]], 5 =>$pointsGROUPED[$row[1].$row[2].$row[3]], 6 => $totalpointsGROUPED[$row[1].$row[2].$row[3]], 7 => $playedGROUPED[$row[1].$row[2].$row[3]], 8 =>$CHIPS); //creates new array combining all the above data

}

I'm pretty new to php and have inherited most of this code, the above are just small sections but I can attach the full code if needed.
Any help would be greatly appreciated.

    Few issues...

    1. Code like this:

      if ($_POST['email']) { 

      is going to generate E_NOTICE level errors if the specified index doesn't exist (e.g. the form hasn't been submitted yet). You should always check to see if external data exists before you attempt to access it, such as by using [man]isset/man or [man]empty/man.

    2. $email = stripslashes($_POST['email']); 
      $email = strip_tags($email);

      Why are you using [man]stripslashes/man here? And [man]strip_tags/man? Neither of those seems necessary or even appropriate.

    3. $password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters 

      Likewise, why on earth would you strip out such characters from a user's password?? In today's world of paranoia and weak passwords, you're intentionally preventing people from using strong passwords by quietly stripping away those characters (so that what I presume to be a strong password of "_super*c(o)[o]l_" is actually nothing more than "supercool" to your application)...

      Oh, and that's not to mention the fact that all of the ereg() functions have been deprecated for some time now in favor of the [man]PCRE[/man] library of functions. 😉

    4. As for the other E_NOTICE level messages, you're defining entries in what appears to be an array, but where do you ever actually initialize the variables $bonusGROUPED, $pointsGROUPED, etc. ... ?

      Not sure if I should hang my head in shame or thank you profusely for all your help!
      I'll go for the latter (I'll do the head hanging later)

      I've not attempted the fixes yet but I will go ahead and do that now so watch out for more questions!

      Thanks for the detailed explaination I really appreciate it.

        Ok Brad got all of that working with the exception of the last point.
        I've updated the code to initialize the variables as follows:

                $bonusGROUPED='';
                $pointsGROUPED='';
                $totalpointsGROUPED='';
                $playedGROUPED='';
                $GBPCPoints='';
                $totalpoints33GROUPED='';
        foreach ($arr as $key => $row) { 										// THIS SECOND LOOP BUILD AN ARRAY FOR EACH PRSON AT EACH VENUE
        																		// ADDING THE POINTS FOR EACH VENUE AND ADDING THE NUMBER OF TIMES
        																		// PLAYED AT EACH VENUE. BEAUTY
        
        
            $bonusGROUPED[$row[1].$row[2].$row[3]] = $bonusGROUPED[$row[1].$row[2].$row[3]] + $row[4] + $row[5]; //grouped data with bonus chips
        $pointsGROUPED[$row[1].$row[2].$row[3]] = $pointsGROUPED[$row[1].$row[2].$row[3]] + $row[6]; //creates grouped data for each player with points
        $totalpointsGROUPED[$row[1].$row[2].$row[3]] = $totalpointsGROUPED[$row[1].$row[2].$row[3]] + $row[4] + $row[5] + $row[6];//creates grouped data for each player with points
        $playedGROUPED[$row[1].$row[2].$row[3]] = $playedGROUPED[$row[1].$row[2].$row[3]] +1; //creates grouped data for number of times played
        $GBPCPoints = $totalpoints33GROUPED[$row[1].$row[2].$row[3]] * $average_by_venue[$row[3]] / 20; // calculates number of chips
        $CHIPS = ceil($GBPCPoints / 25) * 25; //rounds up chipstack to nearest 25		
        
        $arrGROUPED[$row[1].$row[2].$row[3]] =  array(1 => $row[1], 2 => $row[2], 3 => $row[3], 4 => $bonusGROUPED[$row[1].$row[2].$row[3]], 5 =>$pointsGROUPED[$row[1].$row[2].$row[3]], 6 => $totalpointsGROUPED[$row[1].$row[2].$row[3]], 7 => $playedGROUPED[$row[1].$row[2].$row[3]], 8 =>$CHIPS); //creates new array combining all the above data
        
        }
        

        But now I get this error on line 113 to 117 instead:

        Notice: Uninitialized string offset: 0 in C:\web\gbpc\includes\finalists.php on line

        Which are these lines here :

                $bonusGROUPED[$row[1].$row[2].$row[3]] = $bonusGROUPED[$row[1].$row[2].$row[3]] + $row[4] + $row[5]; //grouped data with bonus chips
        	$pointsGROUPED[$row[1].$row[2].$row[3]] = $pointsGROUPED[$row[1].$row[2].$row[3]] + $row[6]; //creates grouped data for each player with points
        	$totalpointsGROUPED[$row[1].$row[2].$row[3]] = $totalpointsGROUPED[$row[1].$row[2].$row[3]] + $row[4] + $row[5] + $row[6];//creates grouped data for each player with points
        	$playedGROUPED[$row[1].$row[2].$row[3]] = $playedGROUPED[$row[1].$row[2].$row[3]] +1; //creates grouped data for number of times played
        	$GBPCPoints = $totalpoints33GROUPED[$row[1].$row[2].$row[3]] * $average_by_venue[$row[3]] / 20; // calculates number of chips
        

        Any idea where I'm going wrong here?
        Thanks a million 🙂

        PS. this is the array:

        while($r = mysql_fetch_array($result)){									// THIS FIRST LOOP CALLCULATES THE CHIP STACK FOR EACH RESULTw
        																		//AND BUILDS ARRAY.
        
        		$arr[] =  array(1 => $r[1], 2 => $r[2], 3 => $r[3], 4 => $r[4], 5 => $r[5], 6 => $r[6], 7 => $r[7]);
        
        // array values are [1]Player.FirstName , [2]Player.LastName,  [3]Venue.VenueName as Venue, [4]Results.MemCard, [5]Results.EarlyReg, [6]Position.Points as Venue_Points, [7]Results.Date
        

          $bonusGROUPED, et al. are being treated as arrays inside that loop, yet you initialized them as strings.

            hehe - I didn't give myself this user name for nothing!

            ok I've swapped it over to initialize as empty arrays like this:

            $bonusGROUPED = array();
                    $pointsGROUPED = array();
                    $totalpointsGROUPED = array();
                    $playedGROUPED = array();
                    $GBPCPoints = array();
                    $totalpoints33GROUPED = array();

            All good, that error has gone away... only I know have this one in it's place, for the same lines!

            Notice: Undefined index: 

            And it seems to be highlighting these as the culprits:

            $row[1].$row[2].$row[3]

            from what I have googled this is because I'm trying to access elements of an array that don't exist, but if I print the array

            print_r($arr);

            everything seems to be populated!

            Any ideas?

              Ok new morning slightly clearer head and I've sorted most of the issues, but every time one gets fixed another appears,
              I'm now getting all of the following errors:

              Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\web\gbpc\includes\finalists.php on line 147
              
              Notice: Undefined variable: arrHIGHEST_RESULT in C:\web\gbpc\includes\finalists.php on line 166
              
              Warning: Invalid argument supplied for foreach() in C:\web\gbpc\includes\finalists.php on line 166
              
              Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\web\gbpc\includes\finalists.php on line 181

              Now clearly something is going on with the array_multisort statements, i've googled all morning and come up with nothing so I'm hoping you guys can help me out again.

              I've resolved the previous errors using

               if (empty($arrHIGHEST_RESULT)) { XXX }

              to wrap my foreach statements and this seems to have sorted all the other issues.

              Thanks a lot

                Write a Reply...