vendredi 27 février 2015

Error in odd spot

I'm trying to debug an error I'm getting:



"Catchable fatal error: Object of class mysqli_result could not be converted to string in /home/dsnook/public_html/SecretSanta/scramble.php on line 69" Line 69 is :$sql="UPDATE users SET GivingGroupNum='$idquery' WHERE Email='$giver'"; and line 38 is: $randnum=rand(0, ($count-1));



So I try to put a var_dump of the variable causing the problem. After I add the var_dump and run it again I get a timeout error for line 38.


This confuses the hell outa me since I change nothing anywhere near or having to do with line 38. Which is where I get the rand value. Below is my entire code for the page.



<?php
session_start();
require('./include/config.inc.php');
if(!isset($_COOKIE['email']))
include('./include/header.html');
else
include('./include/header2.html');


$gname=$_SESSION['gname'];
$orderarray=array();
$gmemberarray=array();
$sql="SELECT GroupMember FROM santagroup WHERE GroupName='$gname'";
$gmemberquery=mysqli_query($link, $sql);
echo "<br><br>";

foreach($gmemberquery as $person){
$gmemberarray[]=$person;
}

//*********************************************************************************************************

//***************************************************************************************************
$neworder=array();
$xcount=count($gmemberarray);
//fill the array with numbers and a setting of false *hasn't been used*
while($xcount>=1){
//$orderarray[($xcount-1)]=arrray();
$orderarray[($xcount-1)][0]=($xcount);
$orderarray[($xcount-1)][1]=false;
$xcount--;
//echo "<br>OrderArray: ".$orderarray[$xcount][0];
}
$xcount=count($gmemberarray);
$count=$xcount;
while($xcount>=1){
R:
$randnum=rand(0, ($count-1));

$rand2=$randnum+1;
if($orderarray[$randnum][1]==true) //If it's already been used get a different number
goto R; //otherwise try again
if($xcount!=($randnum+1)){ //if it's not equal to itself
$neworder[($xcount-1)]=($randnum+1);
$orderarray[$randnum][1]=true;
//echo "<br><br>Neworder ".$xcount.": ".$neworder[($xcount-1)];
}
else
goto R; //otherwise try again
$xcount--;

}
$xcount=count($gmemberarray);
while($xcount>=1){
//echo "<br>xcount: ".$xcount;
$person=$neworder[$xcount-1];
$giver1=$gmemberarray[$xcount-1];
$giver=reset($giver1);
$receiver=reset($gmemberarray[$person]);
//$receiver=reset($receiver1);
echo "<br>Groupname: ".$gname." GiverEmail: ".$giver." ReceiverEmail: ".$receiver;
$sql="INSERT INTO santaset (GroupName, GiverEmail, ReceiverEmail) VALUES ('$gname', '$giver', '$receiver')";
$insertquery=mysqli_query($link, $sql);

$sql="SELECT GroupSetID FROM santaset WHERE GiverEmail='$giver' AND ReceiverEmail='$receiver'";
$idquery=mysqli_query($link, $sql);

//var_dump($idquery);
$sql="UPDATE users SET GivingGroupNum='$idquery' WHERE Email='$giver'";
$setinfo=mysqli_query($link, $sql);
$sql="UPDATE users SET ReceivingGroupNum='$idquery' WHERE Email='$receiver'";
$setinfo=mysqli_query($link, $sql);
$xcount--;
}


?>




Aucun commentaire:

Enregistrer un commentaire