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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    225
    Thanks
    2
    Thanked 0 Times in 0 Posts

    PHP redirect when mysql_connect() is false

    Hello,

    I have been having problems with my host about too many connections so I want to create a page that redirects to a new page when it happens, so it looks more professional, instead of error page.

    Here is my code:
    <? php
    if mysql_connect() == FALSE
    header("Location: www.mysite.com/redirect.php");
    {
    //connection made}
    else { //
    header("Location: www.mysite.com");
    }
    ?>

    I like to ask one question:
    Is this a correct code? and Where should I place this code?

    thanks.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    That's two questions.

    It's correct pseudo-code, but has syntax errors. I'm assuming you're asking about the logic and it looks fine to me.

    To answer the 2nd question, it's confusing why you should be confused about where such code should go, because I would assume you already have code that connects to your MySQL database (and don't you know where this code is?) so therefore it stands to reason you would add this logic to that code which is already in place.

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Posts
    225
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Can you help me how to correct the syntax error?

    For the 2nd question, should I place it under the connect.php file, right? The one that shows errors online?
    thanksl

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Syntax errors would happen because your "if" statement is not correct. You know...

    PHP Code:
    if (condition) {} else {} 
    Yours is
    PHP Code:
    if condition { else {} 


  •  

    Posting Permissions

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