Welcome Guest, Not a member yet? Register   Sign In
Newbie "Logical" Observation: Get your sytax Correct!!!!!!!
#1

[eluser]featureBlend[/eluser]
Im on a local Apache 2.06 / PHP 5.2.6 / MY SQL 5+ Environment

A simple logical observation and explanation ---> I am not using short tags and the tutes that Derek posted do, so if you are in the same position as me then read on..

I had done everything according to the tute, but when i pressed the submit button in the comments_view there was no response..Heres the files BEFORE i figured it out:

1. blog.php (Front Controller)

Code:
<?php
    class Blog extends Controller {
        
        function Blog()
        {
            parent::Controller();
            
            $this->load->scaffolding('entries');
            $this->load->database();
            
            $this->load->helper('url');
            $this->load->helper('form'); //loaded the helpers
        }
        
        function index()
        {
            $data['title']="Ahads Page with CI";
            $data['heading']="My Blog Heading";
            $data['query']= $this->db->get('entries');
            
            
            $this->load->view('blog_view', $data);
        }
        
        function comments()
        {
            $data['title']="My Comment Title";
            $data['heading']="My Comment Heading";
            $this->load->view('comment_view', $data);
        }
        
        function comment_insert()
        {
            echo 'testing 1,2,3'; //lets test that function in the comment_view
        }
}
?>

2. comment_view.php (View file for comment page)

Code:
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1>&lt;?php echo $heading; ?&gt;</h1>

///hmmm what could be wrong with the syntax here?
//should i open the form tag with the html syntax &lt;form&gt;?
//i tried to use the form syntax, the button started working but not quite the way i wanted it
&lt;?php form_open('blog/comment_insert'); ?&gt;

&lt;?php form_hidden('entry_id',$this->uri->segment(3));?&gt;

<p>&lt;textarea name="body" rows="10"&gt;&lt;/textarea></p>
<p>&lt;input type="text" name = "author" /&gt;&lt;/p>
<p>&lt;input type="submit" value="Submit Comment" /&gt;&lt;/p>

&lt;/form&gt;
    

&lt;/body&gt;
&lt;/html&gt;

No response from the Submit button from the above code..Why? I knew it was something with my syntax in one of the files. Was it the &lt;form&gt; tag in the comments_view (but i called the form helper class from the controller so it should handle the request right?, RIGHT), or some other syntax error. See below:

Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<h1>&lt;?php echo $heading; ?&gt;</h1>


&lt;?php echo form_open('blog/comment_insert'); ?&gt;

&lt;?php echo form_hidden('entry_id',$this->uri->segment(3));?&gt;

<p>&lt;textarea name="body" rows="10"&gt;&lt;/textarea></p>
<p>&lt;input type="text" name = "author" /&gt;&lt;/p>
<p>&lt;input type="submit" value="Submit Comment" /&gt;&lt;/p>

&lt;/form&gt;
    

&lt;/body&gt;
&lt;/html&gt;

I failed to add the "echo" STATEMENT before (1) form_open and (2) form_hidden in my comments_view file.

What is the echo statement?

In flat files the syntax would be:

Code:
void echo (string argument [,...string argumentN])

The echo() statement operates similarily to print(), except for two differences.

1 - It cannot be used as a part of a complex expression because it returns void()
2 - echo() is capable of outputting multiple strings (see below)

For example:

Code:
&lt;?php
   $easier = "Code Igniter";
   $harder = "Symfony";
   echo $easier,  " and " , $harder, " are great frameworks. ", " Learn CI first though.....If the dudes who created CI follow the KISS approach, then so shall we. ";
?&gt;

Try to develop good habits and "familiarize" yourself with flat php syntax as well....


Messages In This Thread
Newbie "Logical" Observation: Get your sytax Correct!!!!!!! - by El Forum - 12-01-2008, 02:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB