adamjones Posted October 10, 2008 Share Posted October 10, 2008 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 More sharing options...
AndyB Posted October 10, 2008 Share Posted October 10, 2008 http://www.tizag.com/mysqlTutorial/ - spend a few minutes there and you be fine. Link to comment https://forums.phpfreaks.com/topic/127924-solved-making-a-maintenance-scipt/#findComment-662346 Share on other sites More sharing options...
adamjones Posted October 10, 2008 Author Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127924-solved-making-a-maintenance-scipt/#findComment-662356 Share on other sites More sharing options...
dropfaith Posted October 10, 2008 Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127924-solved-making-a-maintenance-scipt/#findComment-662363 Share on other sites More sharing options...
adamjones Posted October 10, 2008 Author Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127924-solved-making-a-maintenance-scipt/#findComment-662367 Share on other sites More sharing options...
AndyB Posted October 10, 2008 Share Posted October 10, 2008 if($row['check']; == yes) { is wong if($row['check'] == yes) { is good Link to comment https://forums.phpfreaks.com/topic/127924-solved-making-a-maintenance-scipt/#findComment-662369 Share on other sites More sharing options...
dropfaith Posted October 11, 2008 Share Posted October 11, 2008 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 https://forums.phpfreaks.com/topic/127924-solved-making-a-maintenance-scipt/#findComment-662378 Share on other sites More sharing options...
AndyB Posted October 11, 2008 Share Posted October 11, 2008 if($row['check']; == yes) { is wrong I wasn't kidding about this. The ; does not belong. Link to comment https://forums.phpfreaks.com/topic/127924-solved-making-a-maintenance-scipt/#findComment-662390 Share on other sites More sharing options...
dropfaith Posted October 11, 2008 Share Posted October 11, 2008 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 https://forums.phpfreaks.com/topic/127924-solved-making-a-maintenance-scipt/#findComment-662395 Share on other sites More sharing options...
taith Posted October 11, 2008 Share Posted October 11, 2008 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 https://forums.phpfreaks.com/topic/127924-solved-making-a-maintenance-scipt/#findComment-662428 Share on other sites More sharing options...
adamjones Posted October 11, 2008 Author Share Posted October 11, 2008 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 https://forums.phpfreaks.com/topic/127924-solved-making-a-maintenance-scipt/#findComment-662596 Share on other sites More sharing options...
aeonsky Posted October 11, 2008 Share Posted October 11, 2008 Not this... header('location:maintenance.php') ... But this ... header('location:maintenance.php'); Link to comment https://forums.phpfreaks.com/topic/127924-solved-making-a-maintenance-scipt/#findComment-662597 Share on other sites More sharing options...
adamjones Posted October 11, 2008 Author Share Posted October 11, 2008 Thanks for the help guys. Sorted it. Link to comment https://forums.phpfreaks.com/topic/127924-solved-making-a-maintenance-scipt/#findComment-662621 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.