Parse error: syntax error, unexpected T_ENDIF in C:\apachefriends\xampp\htdocs\cms\_class\cms_class.php on line 36 I can't seem to see what's going wrong. Can somebody help me please. cms_class.php <?php class curveCMS { var $host; var $username; var $password; var $db; function connect() { $con = mysql_connect($this->host, $this->username, $this->password); mysql_select_db($this->db, $con) or die(mysql_error()); } function get_content() { $sql = "SELECT * FROM data ORDER BY id DESC"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)) { echo '<h1>' . $row['title'] . '</h1>'; echo '<p>' . $row['body'] . '</p>'; } function get_content($id ='') { function add_content($p) { $title = mysql_real_escape_string($p['title']); $body = mysql_real_escape_string($p['body']); if(!$title || !$body); if(!$title); echo "<p>The title field is required.</p>"; endif; if(!$body); echo "<p>You must add text into the content area in order to publish this</p>"; endif; echo "<p><a href='add-content.php'>Try Again</a></p>"; else; endif; } } } // ENDS OUR CLASS ?> Code (markup):
1) You are the only person on earth to use the "endif" construct. You will probably find life is easier if you use curly braces like everybody else does. 2) You need a colon ) after the "if" part, not a semicolon (.
Edit, nevermind. I decided to go with curly braces. if(!$title) { echo "<p>The title field is required.</p>"; } Code (markup):
you created function add_content inside function get_content.... THAT WON'T WORK!!! class curveCMS { var $host; var $username; var $password; var $db; function connect() { $con = mysql_connect($this->host, $this->username, $this->password); mysql_select_db($this->db, $con) or die(mysql_error()); } function get_content() { $sql = "SELECT * FROM data ORDER BY id DESC"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)) { echo '<h1>' . $row['title'] . '</h1>'; echo '<p>' . $row['body'] . '</p>'; } function get_content($id ='') { } function add_content($p) { $title = mysql_real_escape_string($p['title']); $body = mysql_real_escape_string($p['body']); if(!$title) echo "<p>The title field is required.</p>"; if(!$body) echo "<p>You must add text into the content area in order to publish this</p>"; if(!$body || !$title) echo "<p><a href='add-content.php'>Try Again</a></p>"; } } // ENDS OUR CLASS PHP: try this one.