View Full Version : PHP redirect when mysql_connect() is false

12-15-2010, 03:49 PM

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?


12-15-2010, 04:53 PM
That's two questions. :p

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.

12-15-2010, 05:36 PM
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?

12-15-2010, 10:45 PM
Syntax errors would happen because your "if" statement is not correct. You know...

if (condition) {} else {}

Yours is

if condition { else {}