php errorcode, only with XAMPP (Win 7 32bit) 1.7.7 -[Solved]

Problems with the Windows version of XAMPP, questions, comments, and anything related.

php errorcode, only with XAMPP (Win 7 32bit) 1.7.7 -[Solved]

Postby Havoc » 14. October 2011 03:26

Initially I was working with UniServer, but I found it to be too unreliable for my needs, so I've been looking around for another server to run on. However when I tried XAMPP I get the following error with my script.

Equally, I have tried using Server2Go and found that I have exactly the same problem. I do not understand why the script would run on one server, yet not another. Especially considering that the php/mysql versions are the same with the Uniserver and XAMPP. Here is the error message and the relevant code. If anyone has any ideas, I'd love to hear them.

Thanks


Code: Select all
Notice: Undefined variable: interaction in C:\xampp\htdocs\prog\insert_v4.php on line 88

Warning: array_slice() expects parameter 1 to be array, null given in C:\xampp\htdocs\prog\insert_v4.php on line 88
This is $interactions
$numberOfInteractions = 0


Code: Select all
function sanitize($input) {
    if (is_array($input)) {
        foreach($input as $var=>$val) {
            $output[$var] = sanitize($val);
        }
    }
    else {
        if (get_magic_quotes_gpc()) {
            $input = stripslashes($input);
        }
        $input  = cleanInput($input);
        $output = mysql_real_escape_string($input);
    }
    return $output;
}


// count the length of the $_POST array
$array_length = count($_POST);

if($debugMode == 1) {
   echo('$array_length = ' . $array_length . '<br />');
   print('<b>This is $_POST</b>');
   print('<pre>');
   print_r($_POST);
   print('</pre>');
}

// create a new numerically-indexed array based on $_POST
$p_results = array_values($_POST);

if($debugMode == 1) {
   print('<b>This is $p_results</b>');
   print('<pre>');
   print_r($p_results);
   print('</pre>');
}

// slice out the user-submitted data (i.e. the four indexes before the final index)
$userinfo = array_slice($p_results, -5, -1);

if($debugMode == 1) {
   print('<b>This is $userinfo</b>');
   print('<pre>');
   print_r($userinfo);
   print('</pre>');
}

$interaction = array_slice($interaction, 25, -6);

if($debugMode == 1) {
   print('<b>This is $interactions</b>');
   print('<pre>');
   print_r($interaction);
   print('</pre>');
}

$numberOfInteractions = count($interaction)/10;
if($debugMode == 1) {
   echo('$numberOfInteractions = ' . $numberOfInteractions . '<br />');
}

$numberOfElements = count($interaction);

// select the db
mysql_select_db('cp2db');

// insert the user data into tblperson
$sqlPerson = "INSERT INTO tblperson (personFirstName, personLastName, personInstructor, personCourseCode)
VALUES ('$userinfo[0]','$userinfo[1]','$userinfo[2]','$userinfo[3]')";

if (!mysql_query($sqlPerson,$link)) {
  die('Could not insert data into tblperson.  Died with this error: ' . mysql_error());
} else {
  if($debugMode == 1) {
   print('tblperson values were written.<br />');
  }
}

// slice the results array, removing the coredata (i.e. indexes 0-24)
// and the user-submitted identification data (i.e. the last four indexes + submit + final null)
$interaction = array_slice($p_results, 25, -6);

if($debugMode == 1) {
   print('<b>This is $interactions</b>');
   print('<pre>');
   print_r($interaction);
   print('</pre>');
}

$numberOfInteractions = count($interaction)/10;
if($debugMode == 1) {
   echo('$numberOfInteractions = ' . $numberOfInteractions . '<br />');
}

$numberOfElements = count($interaction);

$sliceStart = 0;
$sliceStop = 10;
for($i = 0; $i<$numberOfInteractions;$i++) {
   $currentInteraction = array_slice($interaction, $sliceStart, $sliceStop);
   
   // prep SQL and intert
   $sqlInteraction="INSERT INTO tblinteraction (
   interactionDate, interactionTime, questionAdobeID, interactionObjectiveID,
   interactionType, questionCorrectResponse, interactionStudentResponse,
   interactionResult, interactionWeight, interactionLatency)
   VALUES (
   '$currentInteraction[0]', '$currentInteraction[1]', '$currentInteraction[2]',
   '$currentInteraction[3]', '$currentInteraction[4]', '$currentInteraction[5]',
   '$currentInteraction[6]', '$currentInteraction[7]', '$currentInteraction[8]',
   '$currentInteraction[9]')";
   
   if (!mysql_query($sqlInteraction,$link)) {
      die('Could not insert data into tblinteraction.  Died with this error: ' . mysql_error());
   } else {
      if($debugMode == 1) {
         print('tblinteraction values were written.<br />');
         print('<b>This is $currentInteraction, from index ' . $sliceStart . ' taking ' . $sliceStop . ' elements</b>');
         print('<pre>');
         print_r($currentInteraction);
         print('</pre>');
      }
   }
   
   // bump up the start value
   $sliceStart = $sliceStart + 10;
   $sliceEnd = $sliceStart + 9;
   If($sliceEnd > $numberOfElements) {
      Break;
   }

}


Would there be some kind of setting that I'd need to enable within XAMPP itsellf, coz I'm really confused!

Thanks again.
Havoc
 
Posts: 3
Joined: 14. October 2011 03:13

Re: php errorcode, only with XAMPP

Postby Sharley » 14. October 2011 03:28

We require your XAMPP version and your Windows Version to provide the correct version support - please read the following Announcements.
viewtopic.php?f=16&t=48331
viewtopic.php?f=16&t=32670

Thanks.
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: php errorcode, only with XAMPP

Postby Havoc » 14. October 2011 03:59

I do apologise!

Here we go:

I am using XAMPP 1.7.7, and yep. I'm using the control panel.
I'm running off Windows 7 32bit

I'll have a close look at some of those search articles tomorrow, quite a few of them are in German mind, which unfortunately is not a strong point of mine. Thanks...
Havoc
 
Posts: 3
Joined: 14. October 2011 03:13

Re: php errorcode, only with XAMPP

Postby Sharley » 14. October 2011 04:02

Select to search in the XAMPP for Windows in English forum, to reduce the clutter, using the advanced search feature as outlind in the How To Search announcement.

Good luck with the search. :)
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: php errorcode, only with XAMPP

Postby Sharley » 14. October 2011 04:12

Havoc wrote:Would there be some kind of setting that I'd need to enable within XAMPP itsellf
Because the warning message did not appear in your other tested severs then that would be because 1.7.7 has a high level of error reporting set for php developers.

To help you save time you can read and select different levels of error reporting (error_reporting) in the C:\xampp\php\php.ini file under this section at about line 462 as you have a [warning] not an actual [error]:
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Make a backup copy of the file before editing, then save the file if you change a setting, restart Apache and try your script again to see if your selection has removed the warning.

Good luck. :)
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: php errorcode, only with XAMPP

Postby Altrea » 14. October 2011 04:55

The notice occures in this line:
Code: Select all
$interaction = array_slice($interaction, 25, -6);


and thats because, there is no definition for $interaction before this line.
Maybe thats an error in the rest of your script (there must be 37+ lines more in your script before, because your error line is 88, mine is 51 with your code you posted here), maybe your hoster just hides notices and warnings.

The Warning is an aftereffect of the missing variable definition. The php function array_slice() needs a array to work with, but because of the missing missing definition, you put in null (which means undefined).

I can't remember Sharleys suggestion to change the error_reporting just to hide the messages too.
You should debug your script and get rid of this error completely. Missing Variable definitions are not only bad programming style, they can be a security risk too.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8299
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: php errorcode, only with XAMPP

Postby Sharley » 14. October 2011 05:10

Hiding the warnings is probably what the OP intended when he first posted and as he suggested, this may not be his own script and therefore he may not know PHP like a PHP geek does. ;)

If the OP new how to debug PHP scripts then he would not have any reason to have posted in here.

Security issues depend on the OP's use of XAMPP and if only developing or testing scripts etc. at localhost level then no problem, but if he intends XAMPP to be open to the Internet as a production server (absolutely not recommended) then he would need to be aware of the security concerns related to how XAMPP is constructed and outlined in these forums and in the readme_en.txt file in the xampp folder.

If the script is a downloaded script then the author of the script may have an updated version that may run better in the PHP environment of 1.7.7.

Making assumptions based on information not supplied is not recommended.



@Havoc,
I recommend you use this setting at about line 516 in the php.ini file, which will give you errors only but eliminate those pesky warnings.
Code: Select all
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR

Good luck :)
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: php errorcode, only with XAMPP

Postby Altrea » 14. October 2011 05:28

Sharley wrote:Security issues depend on the OP's use of XAMPP

That's not why i'm worry about security. XAMPP is quite safe at the topic of undefined variables.
But he uses the script on a webhoster which hided warnings and notices. Many hoster are hiding notices, thats okay. But hoster who are hiding warnings do this very common because of compatibility issues and thats very often the reason for switching on register_globals too. Thats the security issue i see, which is not XAMPP related.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8299
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: php errorcode, only with XAMPP

Postby Sharley » 14. October 2011 05:37

@Havoc.
You will be OK using XAMPP and editing the line I recommend above in the php.ini file to rid yourself of the warnings and notices as your issue is not an error. 8)

Do see if the original author of the script has an upgrade and if not, then be aware of what Altrea has posted about if you use a hosting service, but for your assumed intended use, you will be fine using it in XAMPP.

I await your feedback so this topic can be marked solved which will help others who are reading it or searching the forums for a similar solution.

Thanks and best wishes. :)
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: php errorcode, only with XAMPP

Postby Havoc » 15. October 2011 02:37

Thanks for the wealth of advice guys;

Sharley wrote:
Havoc wrote:Would there be some kind of setting that I'd need to enable within XAMPP itsellf
Because the warning message did not appear in your other tested severs then that would be because 1.7.7 has a high level of error reporting set for php developers.

To help you save time you can read and select different levels of error reporting (error_reporting) in the C:\xampp\php\php.ini file under this section at about line 462 as you have a [warning] not an actual [error]:
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Make a backup copy of the file before editing, then save the file if you change a setting, restart Apache and try your script again to see if your selection has removed the warning.

Good luck. :)


ahaha! You might well be onto something there. Essentially it appears I was just using a naff server prior to this then, thanks for explaining that. I have now edited the INI file to E_ERROR and the Warning message has disappeared.

Yep, I'm no php genius unfortunately! The script is there to take results from Adobe Captivate (which I work in) and dump them to a mySQL database. But thanks for your observations; I'll pass them onto my developer. Security isn't too much of an issue as the file will be used completely offline.

Please do mark this topic as solved, and thanks again for your time.

Havoc
Havoc
 
Posts: 3
Joined: 14. October 2011 03:13

Re: php errorcode, only with XAMPP

Postby Sharley » 15. October 2011 02:50

Thanks for the feedback and I am pleased that you can now move forward, 8)

Enjoy XAMPP.

Best wishes and good luck. :)
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 33 guests