Jump to content

Ideas to make code faster


Grodo

Recommended Posts

Hi,

 

    Ok I have a fuction it works great however its really slow and lags the page.  I was wondering what i could do to speed it up a bit.  I was thinking to make a for loop to check variables such as this:

$sizeBlah=sizeof($message);
$listVars[fname] = "fname";
$listVars[lname] = "lname";
$listMessage[0] = "Please insert you first name";
$listMessage[1] = "Please insert you last name";
for ($blah=0;$blah <=$sizeBlah;$blah++)
{
     global $HTTP_POST_VARS, $error, $print_again, $message;
     // Validate first name
     $error[$listVars[$blah]] = false; 
     if($_POST[$listVars[$blah]]=="") { 
          $error[$listVars[$blah]] = true; 
          $print_again = true; 
          $message[]=$listMessage[$blah]; 
    }
}

 

However I cant get this to work

 

function check_form() 
{ 
global $HTTP_POST_VARS, $error, $print_again, $message;
// Validate first name
$error['fname'] = false; 
    if($_POST["fname"]=="") { 
        $error['fname'] = true; 
        $print_again = true; 
        $message[]="Please insert you first name<br>"; 
    } 
// Validate last name
$error['lname'] = false; 
    if($_POST["lname"]=="") { 
        $error['lname'] = true; 
         $print_again = true; 
        $message[]="Please insert you last name<br>"; 
    } 
//  Validate Address
$error['address1'] = false; 
    if($_POST["address1"]=="") { 
        $error['address1'] = true; 
        $print_again = true; 
        $message[]="Please enter a valid address<br>"; 
    } 
//  Validate City
$error['city'] = false; 
    if($_POST["city"]=="") { 
        $error['city'] = true; 
        $print_again = true; 
        $message[]="Please enter a valid city<br>"; 
    }
//  Validate State
$error['state'] = false; 
    if($_POST["state"]=="") { 
        $error['state'] = true; 
        $print_again = true; 
        $message[]="Please enter a valid State or Territory<br>"; 
    }
// Validate Country
$error['country'] = false; 
    if($_POST["country"]=="") { 
        $error['country'] = true; 
        $print_again = true; 
        $message[]="Please enter a valid country<br>"; 
    }
// Validate Postal code
$error['zip'] = false; 
    if($_POST["zip"]=="") { 
        $error['zip'] = true; 
        $print_again = true; 
        $message[]="Please enter a valid zip<br>"; 
    }
}

Link to comment
Share on other sites

I run similar scripts on my host all the time, and they run very very quick...  so its almost definately your host...  Only time I ever have issues with mine is if the server has a process running thats causing an unusually high server load...

 

So my bet: your host is garbage and you should consider switching...  I can hook ya up with mine if ya want -- they're pretty cheap and freaking awesome.

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.