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.