[HELP] Parse error: syntax error, unexpected T_ENDIF

Discussion in 'PHP' started by Logitec, Jan 24, 2010.

  1. #1
    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):
     
    Logitec, Jan 24, 2010 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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 (;).
     
    Last edited: Jan 24, 2010
    SmallPotatoes, Jan 24, 2010 IP
  3. Logitec

    Logitec Active Member

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Edit, nevermind. I decided to go with curly braces.

    
     if(!$title) {
    	   echo "<p>The title field is required.</p>";
    	   }
    
    Code (markup):
     
    Logitec, Jan 25, 2010 IP
  4. blacksheep666

    blacksheep666 Active Member

    Messages:
    68
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #4
    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.
     
    blacksheep666, Jan 26, 2010 IP