Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Php Loop Prob

  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts

    Php Loop Prob

    hi

    in this whole function is my limit mod, seems to have a prob looping.

    PHP Code:
        public function doSubmit() {
            if(!empty(
    $_POST)) {
            
    $titles $_POST['title'];
            
    $urls $_POST['url'];
            
    $types $_POST['type'];
            
    $sname $_POST['sname'];
            
    $surl $_POST['surl'];
            
    $email $_POST['email'];
                if(empty(
    $titles[0]) || empty($urls[0]) || empty($types[0]) || empty($sname) || empty($surl) || empty($email)) {
                    
    $this->error 'Error: Some fields were not set, please check you filled in all details.';
                } else {
                    
    $surl $this->purl(str_replace("www.","",$surl),"host");
                    
    $durl $this->purl(str_replace("www.","",$urls[0]),"host");
                    
    $subContinue true;
                    if(
    $this->blackorwhite == "black" && @mysql_num_rows(mysql_query("SELECT url FROM wcddl_blacklist WHERE url = '".mysql_real_escape_string($surl)."'"))) {
                        
    $subContinue false;
                        
    $this->error 'You have been blacklisted, please email the admin for more information.';
                    } elseif(
    $this->blackorwhite == "white" && !@mysql_num_rows(mysql_query("SELECT url FROM wcddl_whitelist WHERE url = '".mysql_real_escape_string($surl)."'"))) {
                        
    $subContinue false;
                        
    $this->error 'You must be whitelisted to submit downloads. Email the admin to be added to the list.';
                    }
                    if(
    $surl != $durl) {
                        
    $subContinue false;
                        
    $this->error .= '<br>Download URL does not match Site URL.';
                    }
                    
    $this->processHook("submitChecks");
                    
    $checksPass = array(
                        
    'status' => $subContinue,
                        
    'site' => array(
                            
    'sname' => $sname,
                            
    'surl' => $surl,
                            
    'email' => $email
                        
    ),
                        
    'downloads' => array(
                            
    'titles' => $titles,
                            
    'urls' => $urls,
                            
    'types' => $types
                        
    )
                    );
                    
    // Var names getting lengthy here :o
                    
    $subContinueHook $this->processDataHook("submitChecksPass",$checksPass);
                    
    $subContinue = isset($subContinueHook['status']) ? $subContinueHook['status'] : $subContinue;
                    if(
    $subContinue) {
                        
    $inserted = array('details' => array(), 'downloads' => array());
                        
    $checkSite mysql_query("SELECT id FROM wcddl_sites WHERE url = '".mysql_real_escape_string($surl)."'");
                        if(@
    mysql_num_rows($checkSite)) {
                            
    $checkSite mysql_result($checkSite,0);
                        } else {
                            
    $checkSite false;
                            
    mysql_query("INSERT INTO wcddl_sites (name,url,email) VALUES ('".mysql_real_escape_string($sname)."','".mysql_real_escape_string($surl)."','".mysql_real_escape_string($email)."')");
                        
    sendwelcomeemail($email,$surl,$pass);
                        }
                        
    $sid = ($checkSite) ? $checkSite mysql_insert_id();
                        
    $inserted['details'] = array(
                            
    "sname" => $sname,
                            
    "surl" => $surl,
                            
    "email" => $email,
                            
    "sid" => $sid
                        
    );
                        
                        
    //$subLimitHook = $this->processDataHook("submissionLimit",$checksPass);
                        
                        // 24 hour mod start, rewritten and optimized by Chris.
                        //Get time and call for last 24 hr time stamp.
                        
    $Time time();
                        
    $Day = (60*60*24);
                        
    $Time = ($Time $Day);
                        
    $subLimit 120;
                        
    $site mysql_real_escape_string($_POST['surl']);
                        
                        
    //Lookup site and get its ID for next 2 queries
                        
    $querySite = ("SELECT * FROM wcddl_sites WHERE name = '".$site."'");
                        
    $resultSite mysql_query($querySite);
                        
    $rowSite mysql_fetch_array($resultSite);
                        
                        
    //Get number of downloads already stored within last 24hrs
                        
    $queryDownloads = ("SELECT * FROM wcddl_downloads WHERE sid = '".$rowSite['id']."' and dat > '".$Time."'");
                        
    $resultDownloads mysql_query($queryDownloads);
                        
                        
    //Get number of downloads in queue already stored within last 24hrs
                        
    $queryQueue = ("SELECT * FROM wcddl_queue WHERE sid = '".$rowSite['id']."'");
                        
    $resultQueue mysql_query($queryQueue);
                        
                        for(
    $i=0;$i<=count($titles)-1;$i++) {
                            if(!
    $this->allow_dupes) {
                                unset(
    $downDupe);
                                
    $downDupe mysql_query("SELECT COUNT(*) FROM wcddl_downloads WHERE url = '".mysql_real_escape_string($urls[$i])."'");
                                
    $downDupe mysql_result($downDupe,0);
                                if(
    $downDupe 1)
                                    unset(
    $downDupe);
                            }
                            if(!empty(
    $titles[$i]) && !empty($urls[$i]) && !empty($types[$i]) && (in_array(strtolower($types[$i]),$this->allowed_types) || in_array($types[$i],$this->allowed_types)) && !isset($downDupe)) {
                                
    mysql_query("INSERT INTO wcddl_queue (sid,title,type,url) VALUES ('".mysql_real_escape_string($sid)."','".mysql_real_escape_string($titles[$i])."','".mysql_real_escape_string($types[$i])."','".mysql_real_escape_string($urls[$i])."')");
                            
                        if (!
    $countQueue mysql_num_rows($resultQueue) && !$countDownloads mysql_num_rows($resultDowloads)) {
                            
    $countQueue 0//If nothing in queue and mysql_num_rows returns false, set to 0
                            
    $countDownloads 0;
                        }
                        
                        
    //Get total count of everything submitted in last 24 hrs (inc queued items that have been submitted anytime)
                        
    $totalCount = ($countQueue $countDownloads);
                        
    //If total submitted items more than allowed.
                        
    if ($totalCount >= $subLimit) {
                            
    //Print error, break out and process no more
                            
    $output '<center><div class="error_message">You can not submit any more downloads as you have reached your daily limit.</div></center>';
                            break;
                        }
                        
                        
    $totalCount++;
                                
                        
    $amountLeft = ($subLimit $totalCount);
                                
                        
    $output '<center><div class="success_message">'.$totalCount.' downloads were successfully submitted in the last 24 hours!<br> You have '.$amountLeft.' of '.$subLimit.' submissions left.</div></center>';
                        
    // 24 hour mod end, rewritten and optimized by Chris.

                                
    $inserted['downloads'][] = array(
                                    
    "title" => $titles[$i],
                                    
    "url" => $urls[$i],
                                    
    "type" => $types[$i],
                                );
                            }
                        }
                        
    $subSuccessHook $this->processDataHook("submitSuccess",$inserted);
                        
    $subSuccess 'Downloads submitted successfully!<br />' .$message;
                    }
                }
            }
            
    $this->processHook("submitEnd");
            return 
    $subSuccess;
        } 
    when i refresh from submitting 3 titles from 1 go, it shud say 6 but its staying at 3.......

    any help.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,441
    Thanks
    62
    Thanked 537 Times in 524 Posts
    Chris,

    Try looking at my codingstyles signature link and reformatting the code as shown. There is a reason why { and } should be on their own lines and indented as explained in the topic. It makes things much easier to read and debug.

    If you do that and still have trouble then get back to me. Sorry for the delay replying to your last PM.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •