Jump to content


Photo

Recursive Error


  • Please log in to reply
2 replies to this topic

#1 gub

gub
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 April 2006 - 02:49 PM

Hi,

I've been trawling through this script for a fair few hours now trying to find the error. I've made code hacks and all sorts to it, but have not had any luck yet.

If someone can find the problem with it, that would be much appreciated!

I have commented the code as best I can - if you need clarification - just let me know and I'll try to provide it.

Many thanks to those who have a look.

Regards,
Matt Wombell

<?php
$link = mysql_connect('localhost', 'xxx', 'xxx')
   or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('xxx') or die('Could not select database');
//IGNORE UNTIL FURTHER NOTICE....

note: values for $u, $s, $t, $p, $e, $randcheck, $row are all taken from the db in the missing code below
.
.
. - code removed - site security check!
.
.

//users table query
$usertable = "SELECT * FROM `users` WHERE userid='$u'";
$getuser = mysql_query($usertable);
$gotuser = mysql_fetch_array($getuser);
$user = $gotuser['fname'];

//schools table query
$schoolstable = "SELECT * FROM `schools` WHERE schid='$s'";
$getsch = mysql_query($schoolstable);
$gotsch = mysql_fetch_array($getsch);
$sch = $gotsch['school'];

$continue = 0;

//check the tutor password
$tutorpass = $_POST['tutorpass'];
$checktutorpass = "SELECT * FROM `users` WHERE userid='$u'";
$tutorpasssql = mysql_query($checktutorpass);
$tutorpassfetch = mysql_fetch_array($tutorpasssql);
$tutorpasstext = $tutorpassfetch['password'];
if (strcmp($tutorpass,$tutorpasstext) == 0) {
    $continue = 1;
}
else {
    echo "wrong password";
}

//if tutor password is ok, then continue...
while ($continue == 1) {
    //get box and list values (numerical) from form posted
    $boxid = $_POST['boxname'];
    $listid = $_POST['listname'];
    echo "listid: $listid<br>";
    echo "boxid: $boxid<br>";
    
    //add the listid to the box sql table
    $grabboxsql = "SELECT * FROM `boxinfo` WHERE `boxno` = $boxid";
    $doboxsql = mysql_query($grabboxsql);
    $gotboxsql = mysql_fetch_array($doboxsql);
    
    //find list number to assign as (iterate until an empty '$slid' value is found)
    $sl = 1;
    while ($sl <= 10){
        $slid = "sl".$sl;
        $whatsl = $gotboxsql["$slid"];
        if ($whatsl == 0) {
            //update the sl(X) value
            $updatelist = "UPDATE `boxinfo` SET `$slid` = '$listid' WHERE `boxno` = '$boxid'";
            $doupdatelist = mysql_query($updatelist);
            $doneanupdate = 1;
            break 2; //break out of the two while statements
        }
        else {
            $sl = $sl + 1; //otherwise iterate until an empty '$slid' is found
        }
    }
}

//continues if an update has been done to the '$slid'...
while ($doneanupdate == 1) {    
    //find users on the list that has been added to sl(X)
    $findusersonlist = "SELECT * FROM `lists` WHERE `listid` = '$listid'";
    $findusersonlistsql = mysql_query($findusersonlist);
    $findusersonlistarray = mysql_fetch_array($findusersonlistsql);
    
    //find the users in the list (in array order e.g. 1,3,4,5)
    $fuol = 1;
    while ($fuol <= 100) {
        $fuoluser = "userid".$fuol;
        $fuolvalue = $findusersonlistarray["$fuoluser"];

        //finds when a userid is not 0
        while ($fuolvalue > 0) {
            //find first available row with '0' in it
            $space = 0;
            while ($space < 500) {
                $findingspace = "SELECT * FROM `userlists` WHERE `userid` = '$fuol'";
                $findingspacesql = mysql_query($findingspace);
                $findingspacearray = mysql_fetch_array($findingspacesql);
                                
                $spacevalueid = "box".$space;
                $spacevalue = $findingspacearray["$spacevalueid"];
                if ($spacevalue == 0) {
                    //if empty one is found, update the list value in the `userlists` table
                    $updatespace = mysql_query("UPDATE `userlists` SET `$spacevalueid` = '$boxid' WHERE `userid` = '$fuol'");
                    //set the update pointer
                    $doneanotherupdate = 1;
                    //echo to say completed and what action done
                    echo "done an insert at $spacevalueid = $boxid where userid = $fuol<br>";
                    break 2; //break out of the two while statements
                }
                else {
                    $space = $space + 1; //otherwise iterate
                }
            }
            
        }
        $fuol = $fuol + 1; //iterate $fuol to get new $fuol value to continue thru the array values
    }
}
//echo statements to show that the script has completed
echo "i think i've inserted the sl value - but please check `boxinfo`!<br>";
echo "done insert of values to users - check - i may be lying!";

/* the issues:

    will work up to the point where it searches through values that are not in the array and ends up in a loop

*/
?>


#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 17 April 2006 - 02:54 PM

What errors are returned?
follow me on twitter @PHPsycho

#3 gub

gub
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 April 2006 - 03:05 PM

[!--quoteo(post=365533:date=Apr 17 2006, 03:54 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Apr 17 2006, 03:54 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
What errors are returned?
[/quote]


Right,

When inserting the values of
$listid = 9
&
$boxid = 3
, (which gets array values of 1,3,4 and 5 at
$findusersonlistarray = mysql_fetch_array($findusersonlistsql);

the code as it stands runs and inserts the values for $fuol = 1 and $fuol = 3, then returns to $fuol = 1 again and then keeps looping until I intervene and press stop in the browser.

That help?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users