Jump to content

[SOLVED] Making A Maintenance Scipt


adamjones

Recommended Posts

Hi.

 

A while ago, I posted a topic on how I could do a maintenance script effectively. What I want to know is, couls someone help me with making a script that checks a table in my database to see if 'maintenance' is set to 'yes' or 'no.

 

I have the following ode in the header of my pages;

 

<?PHP include("check.php"); ?>
<?PHP if(MAINTENANCE == true) {
header('location:maintenance.php');
die();
}
?>

 

And this is my 'check.php' file;

 

<?PHP

define('MAINTENANCE', false);

?>

 

So I'm assuming I just connect to my database in the 'check.php' file- I just dont know how to connect, drag the info from the database, and redirect depending on the info.

 

Any help would be great!

Link to comment
Share on other sites

Ok.

 

I read up on it, and had a go. I got this error;

 

Parse error: syntax error, unexpected ';' in /home/wowdream/public_html/domaine/check.php on line 9

 

This is my header;

 

<?PHP include("check.php"); ?>

 

And this is my 'check.php';

 

<?php
mysql_connect("localhost", "wowdream_domaine", "PASS") or die(mysql_error());
mysql_select_db("maintenance") or die(mysql_error());

$result = mysql_query("SELECT * FROM check") 
or die(mysql_error());  

while($row = mysql_fetch_array( $result )) {
if($row['check']; == yes) {
header('location:maintenance.php');
die();
}
?>

 

Could you tell me what I'm doing wrong please, and would that code work?

Link to comment
Share on other sites

this is probably messy cause i just wrote it but it should work 

<?php

mysql_connect("localhost", "wowdream_domaine", "PASS") or die(mysql_error());
mysql_select_db("maintenance") or die(mysql_error());


// generate and execute query				

	$query = "SELECT * FROM DATABASE TABLE NAME  WHERE FIELD = 'YES'";

	$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());


// if records present
if (mysql_num_rows($result) > 0)
{
// iterate through resultset
// print article titles
while($row = mysql_fetch_object($result))
{
?>
<!--ECHO OUT DATA HERE -->
<?php echo $row->Title; ?>
<!-- end echo and close db connect -->
<?php
}
}
// if no records present
// display message
else
{
?>
No record found display error here 
<?php
}

// close database connection
mysql_close($connection);
?>

Link to comment
Share on other sites

Hi.

 

Thanks, but would it be possible for it just to see if 'yes' is set in the table, and if it is, redirect to 'maintenance.php', or if it's set to 'no', just do nothing?

 

Sorry, I don't have a lot of experience with PHP, but I guess we all have to start somewhere.

Link to comment
Share on other sites

im thinking try  something like this

 

<?php
mysql_connect("localhost", "wowdream_domaine", "PASS") or die(mysql_error());
mysql_select_db("maintenance") or die(mysql_error());

$result = mysql_query("SELECT * FROM check") 
or die(mysql_error());  

while($row = mysql_fetch_array( $result )) {
if($row['check']; == yes) {
header('location:maintenance.php');
}

if($row['check']; == no) {
header('location:KICK USER SOMEWHERE ELSE');
}
}
?>



Link to comment
Share on other sites

it wouldnt let me modify try this

<?php
mysql_connect("localhost", "wowdream_domaine", "PASS") or die(mysql_error());
mysql_select_db("maintenance") or die(mysql_error());

$result = mysql_query("SELECT * FROM check") 
or die(mysql_error());  

while($row = mysql_fetch_array( $result )) {
if($row['check']; == yes) {
   header('location:maintenance.php')
}

if($row['check']; == no) {
   header('location:KICK USER SOMEWHERE ELSE')
}
}
?>

Link to comment
Share on other sites

remove the colon after your variables!

 

<?php
mysql_connect("localhost", "wowdream_domaine", "PASS") or die(mysql_error());
mysql_select_db("maintenance") or die(mysql_error());

$result = mysql_query("SELECT * FROM check") or die(mysql_error());  

while($row = mysql_fetch_assoc($result)) {
if($row['check'] == yes) {
   header('location:maintenance.php')
}else{
   header('location:KICK USER SOMEWHERE ELSE');
}
}
?>

Link to comment
Share on other sites

Ok.

 

I'm getting this error;

 

Parse error: syntax error, unexpected '}' in /home/wowdream/public_html/domaine/check.php on line 10

 

This is my code;

 

<?php
mysql_connect("localhost", "wowdream_domaine", "PASS") or die(mysql_error());
mysql_select_db("maintenance") or die(mysql_error());

$result = mysql_query("SELECT * FROM check") or die(mysql_error());  

while($row = mysql_fetch_assoc($result)) {
if($row['check'] == yes) {
   header('location:maintenance.php')
}else{
   header('location:blah.php');
}
}
?>

 

I've tried removing one of the '}', before the end of the code, but that didn't work..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.