Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-15-2012, 07:17 PM   PM User | #1
Chris-2k
Regular Coder

 
Join Date: May 2011
Posts: 303
Thanks: 29
Thanked 0 Times in 0 Posts
Chris-2k is an unknown quantity at this point
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.
Chris-2k is offline   Reply With Quote
Old 01-19-2012, 04:48 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,521
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:06 AM.


Advertisement
Log in to turn off these ads.