Results 1 to 15 of 15
  1. #1

    * [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.

  2. #2
    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
    Ezeelogin - The ultimate multiple server administration software.
    * Parallel shell * rm -rf protection * SSH logging * automated password changes * encrypted storage *
    AdMod.com - Delivering innovative web hosting solutions

  3. #3
    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"); }

  4. #4
    no one can help?

  5. #5
    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");


    Ezeelogin - The ultimate multiple server administration software.
    * Parallel shell * rm -rf protection * SSH logging * automated password changes * encrypted storage *
    AdMod.com - Delivering innovative web hosting solutions

  6. #6
    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

  7. #7
    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

    }

  8. #8
    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

  9. #9
    BTW the 2 I've tried aren't working. It's loading index.php without sql, and not redirecting

  10. #10
    Warning: Cannot modify header information - headers already sent by (output started at /home/kohkinda/public_html/xxxxxxx/inc/db2.php:15) in

  11. #11
    comeon guys

  12. #12
    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
    And then include this file in all pages where ever you need the DB connection stuff.

  13. #13
    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.

  14. #14
    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.

    ?>

  15. #15
    Join Date
    Nov 2001
    Location
    Vancouver
    Posts
    2,422
    Quote Originally Posted by kohkindachi View Post
    comeon guys
    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.”

Posting Permissions

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