Jump to content

Recursive Error


gub

Recommended Posts

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

[code]
<?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

*/
?>[/code]
Link to comment
Share on other sites

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


Right,

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

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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.