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
https://forums.phpfreaks.com/topic/127924-solved-making-a-maintenance-scipt/
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?

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);
?>

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.

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');
}
}
?>



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')
}
}
?>

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');
}
}
?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.