You are here:  » message if database table doesn´t exist

Support Forum



message if database table doesn´t exist

Submitted by Harry on Fri, 2009-02-20 11:16 in

Hi David,

if a table doesn´t exist in the database, a warning messing like this is displayed:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/includes/database.php on line 21

Instead of this warning message, I would like to display a new html page with the message
"Site is in maintenance !"

How can I do this? What I have to change in database.php?

Submitted by support on Fri, 2009-02-20 11:48

Hi Harry,

Assuming this is intentional, you could do this easily by sending a redirect to your maintenance HTML page if a database query fails. In includes/database.php, you will see this code on line 17:

  $result = mysql_query($sql,$link);

...simply REPLACE this with:

  $result = mysql_query($sql,$link);
  if (!$result)
  {
    header("Location: /maintenance.html");
    exit();
  }

Cheers,
David.

Submitted by Harry on Fri, 2009-02-20 12:44

This replacement with header doesn´t work for me...

Warning: Cannot modify header information - headers already sent by (output started at /home/html/header.php:12)...

Submitted by support on Fri, 2009-02-20 12:57

Hi Harry,

For database queries that take place after the output has begun the only option to use a JavaScript redirect. Try it like this instead of the above code:

  $result = mysql_query($sql,$link);
  if (!$result)
  {
    print "<script type='text/JavaScript'>window.location='/maintenance.html';</script>";
    exit();
  }

Cheers,
David.