mikeytrieb Posted August 27, 2014 Share Posted August 27, 2014 (edited) Hey guys, need some help real quick. I'm using this walkthrough over at css-tricks, some might be familiar with it by now? Anyway, I've followed the instructions exactly. It's supposed to display a simple form that you fill out and submit, which then updates the MYSQL database. However, whenever i load display.php in my browser, all i get is a blank page, and there are no notifications or errors to be in seen in the console. Any help is greatly appreciated. Thanks! Here's my code: SimpleCMS.zip display.php <!DOCTYPE html> <html lang="en"> <head> <title>SimpleCMS</title> </head> <body> <?php include_once('_class/simpleCMS.php'); $obj = new simpleCMS(); $obj->host = 'localhost'; $obj->username = 'root'; $obj->password = 'root'; $obj->table = 'test'; $obj->connect(); if ( $_POST ) $obj->write($_POST); echo ( $_GET['admin'] == 1 ) ? $obj->display_admin() : $obj->display_public(); ?> </body> </html> _class/simpleCMS.php <?php class simpleCMS { var $host; var $username; var $password; var $table; public function display_public() { $q = "SELECT * FROM testDB ORDER BY created DESC LIMIT 3"; $r = mysql_query($q); if ( $r !== false && mysql_num_rows($r) > 0 ) { while ( $a = mysql_fetch_assoc($r) ) { $title = stripslashes($a['title']); $bodytext = stripslashes($a['bodytext']); $entry_display .= <<<ENTRY_DISPLAY <h2>$title</h2> <p> $bodytext </p> ENTRY_DISPLAY; } } else { $entry_display = <<<ENTRY_DISPLAY <h2>This Page Is Under Construction</h2> <p> No entries have been made on this page. Please check back soon, or click the link below to add an entry! </p> ENTRY_DISPLAY; } $entry_display .= <<<ADMIN_OPTION <p class="admin_link"> <a href="{$_SERVER['PHP_SELF']}?admin=1">Add a New Entry</a> </p> ADMIN_OPTION; return $entry_display; } public function display_admin() { return <<<ADMIN_FORM <form action="{$_SERVER['PHP_SELF']}" method="post"> <label for="title">Title:</label> <input name="title" id="title" type="text" maxlength="150" /> <label for="bodytext">Body Text:</label> <textarea name="bodytext" id="bodytext"></textarea> <input type="submit" value="Create This Entry!" /> </form> ADMIN_FORM; } public function write($p) { if ( $p['title'] ) $title = mysql_real_escape_string($p['title']); if ( $p['bodytext']) $bodytext = mysql_real_escape_string($p['bodytext']); if ( $title && $bodytext ) { $created = time(); $sql = "INSERT INTO testDB VALUES('$title','$bodytext','$created')"; return mysql_query($sql); } else { return false; } } public function connect() { mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error()); mysql_select_db($this->table) or die("Could not select database. " . mysql_error()); return $this->buildDB(); } private function buildDB() { $sql = <<<MySQL_QUERY CREATE TABLE IF NOT EXISTS testDB ( title VARCHAR(150), bodytext TEXT, created VARCHAR(100) ) MySQL_QUERY; return mysql_query($sql); } } ?> Edited August 27, 2014 by mikeytrieb Quote Link to comment https://forums.phpfreaks.com/topic/290665-following-simple-cms-tutorial-page-loads-blank/ Share on other sites More sharing options...
trq Posted August 27, 2014 Share Posted August 27, 2014 Sorry, but that code is terribly dated and isn't really a good example to begin with. Why learning php from a css site seemed like a good idea I'm not sure. Anyway, its seems you have display_errors switched of and maybe have error_reporting set too low. Check your php.ini which is well commented, and fix. Quote Link to comment https://forums.phpfreaks.com/topic/290665-following-simple-cms-tutorial-page-loads-blank/#findComment-1489017 Share on other sites More sharing options...
ginerjm Posted August 27, 2014 Share Posted August 27, 2014 (edited) to enable error reporting place this at the top of your php: error_reporting(E_ALL | E_NOTICE); ini_set('display_errors','1'); AND - if trq (note his experience level!) says your code is out-dated, you are definitely driving down a dead-end road here. Get a newer tutorial. Edited August 27, 2014 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/290665-following-simple-cms-tutorial-page-loads-blank/#findComment-1489063 Share on other sites More sharing options...
Jacques1 Posted August 27, 2014 Share Posted August 27, 2014 The author himself actually warns you that the code is full of security issues, the comments make it very clear that the whole tutorial is bullshit, and the text is more than 5 years old. Why on earth would you pick that tutorial? What do you expect to learn? How to write crap code? Quote Link to comment https://forums.phpfreaks.com/topic/290665-following-simple-cms-tutorial-page-loads-blank/#findComment-1489081 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.