Results 1 to 15 of 15
-
06-16-2009, 07:51 AM #1Junior Guru
- Join Date
- Apr 2006
- Posts
- 185
[URGENT] Advice on redirecting following a sql connection error
Hey guys my server is now facing some problems with sql connection, It's now showing simple connection error message I've set. Can u guys advice on how can I redirect to other page like http://websiteabc.com/maintenance.php?
This is my coding
PHP Code:$dbHost = '';
$dbUser = '';
$dbPass = '';
$dbName = '';
mysql_connect($dbHost, $dbUser, $dbPass) or die('A database connection could not be established, please try again later.');
mysql_select_db($dbName) or die('A database connection could not be established, please try again later.');
Last edited by kohkindachi; 06-16-2009 at 07:56 AM.
-
06-16-2009, 08:18 AM #2Newbie
- Join Date
- Jun 2009
- Posts
- 28
make sure that Your host name,db user name ,password are correct...
have you ever connected mysql(backend) using these values ?
you can use die(mysql_error()) for finding the correct error...
hope this helps you
-
06-16-2009, 08:19 AM #3Junior Guru
- Join Date
- Apr 2006
- Posts
- 185
Thanks. I know the problem. But I just want to redirect user to a proper page.
will this works?
$conn = mysql_connect($dbHost, $dbUser, $dbPass); if($conn) { if(!mysql_select_db($dbname)) header("location:error.php"); } else { header("location:error.php"); }
-
06-16-2009, 08:39 AM #4Junior Guru
- Join Date
- Apr 2006
- Posts
- 185
no one can help?
-
06-16-2009, 08:45 AM #5Newbie
- Join Date
- Jun 2009
- Posts
- 28
try this code it will work ..make sure that $dbHost contains atleast some value..
PHP Code:$dbHost = 'xxx';
$dbUser = '';
$dbPass = '';
$dbName = '';
$conn = mysql_connect($dbHost, $dbUser, $dbPass);
if($conn) {
if(!mysql_select_db($dbName)) header("location:dberror.php"); else header("location:success.php");
}
else {
header("Location:error.php");
}
-
06-16-2009, 08:48 AM #6Junior Guru
- Join Date
- Apr 2006
- Posts
- 185
The connection will be placed on needed pages, so how can i can removed success.php?
If i placed it on index.php, I don't want it to be redirected to success.php when connection resumes. And because this db.php is added as 'include', i don't to add the page link manually too
-
06-16-2009, 08:53 AM #7Temporarily Suspended
- Join Date
- Apr 2009
- Location
- localhost
- Posts
- 175
You may need some thing like this
PHP Code:<?php
ob_start(); // start the buffer for redirection purpose
$dbHost = 'localhost';
$dbUser = 'username';
$dbPass = 'password';
$dbName = 'dbname';
$conn = mysql_connect($dbHost, $dbUser, $dbPass);
if($conn) {
if(!mysql_select_db($dbName)){
header("location:error.php?msg=dbselecterr"); // get the message to display error ie could not select DB error
}else { header("location:index.php"); // this means success.
}
}else {
header("Location:error.php?msg=conerr"); // get the message to display error ie connection error
}
-
06-16-2009, 08:56 AM #8Junior Guru
- Join Date
- Apr 2006
- Posts
- 185
Thanks alot. But like isaid, I've many pages that need db connection, like page1.php and page2.php and I add them using include(db.php)
so i can't keep 'index.php' on the success part
-
06-16-2009, 09:12 AM #9Junior Guru
- Join Date
- Apr 2006
- Posts
- 185
BTW the 2 I've tried aren't working. It's loading index.php without sql, and not redirecting
-
06-16-2009, 09:23 AM #10Junior Guru
- Join Date
- Apr 2006
- Posts
- 185
Warning: Cannot modify header information - headers already sent by (output started at /home/kohkinda/public_html/xxxxxxx/inc/db2.php:15) in
-
06-16-2009, 09:32 AM #11Junior Guru
- Join Date
- Apr 2006
- Posts
- 185
comeon guys
-
06-16-2009, 09:43 AM #12Temporarily Suspended
- Join Date
- Apr 2009
- Location
- localhost
- Posts
- 175
on your db2.php file you will have to use
PHP Code:<?php
ob_start();
// your DB details like hostname, username , passwordetc
-
06-16-2009, 09:53 AM #13Junior Guru
- Join Date
- Apr 2006
- Posts
- 185
Warning: Cannot modify header information - headers already sent by (output started at /home/kohkinda/public_html/xxxxxxxx/config.php:54) in
This is what i have on index.php
<?php
include("config.php");
include("db2.php");
?>
Config.php contains basic variables to be used on all pages like ads code, meta desc etc.
-
06-16-2009, 10:03 AM #14Temporarily Suspended
- Join Date
- Apr 2009
- Location
- localhost
- Posts
- 175
I see then you must give
ob_start(); at the config.php right below the php start tag
<?php
ob_start();
// your conf vars.
?>
-
06-16-2009, 10:47 AM #15Web Hosting Master
- Join Date
- Nov 2001
- Location
- Vancouver
- Posts
- 2,422
If you don't want to take the time to understand basic web programming, why are you doing basic web programming?
And instead of being impatient and rude (demanding an answer in less than 10 minutes from a forum, for free, is pretty rude in my books), why not Google for the cause and at least *attempt* to find your own answer? This isn't that tough:
http://lmgtfy.com/?q=Cannot+modify+h...lready+sent+by (only 3.2 million hits with hints and answers in the first few links and probably many more within the 3.2M hits...)
If you are not willing to help in helping yourself...Last edited by mwatkins; 06-16-2009 at 10:55 AM.
“Even those who arrange and design shrubberies are under
considerable economic stress at this period in history.”