Welcome Guest, Not a member yet? Register   Sign In
Parse error: syntax error, unexpected $end caused by foreach in view
#1

[eluser]swgj19[/eluser]
Codeigniter Vs. 2.0

Oh right. I basically queried my database in my model. Then in my controller I called my model. And then I called the string as $row in a foreach in my view. I am getting that basic old error and I cannot figure out why. I commented out the foreach on my view and the error goes away. So I know where the error is caused, but cannot figure out how to keep my foreach loop in my view without the error. Thanks guys..

Here is the full error:
Parse error: syntax error, unexpected $end in /home/content/70/6930870/html/tt/application/views/logged_in_area.php on line 28

Here is my model:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Membership_model extends CI_Model {


function validate()
{
  $this->db->where('username', $this->input->post('username'));  //validate username
  $this->db->where('password', md5($this->input->post('password'))); //validate password
  $query = $this->db->get('membership');        //get db table
  
  if($query->num_rows == 1)           //Make sure data in table exist
  {
   return true;             //if data in table, then return results
  }
}
function create_member()
  {
  $new_member_insert_data = array(         //if validation passed (line 57 controller/login.php), post array data to db
   'first_name' => $this->input->post('first_name'),
   'last_name' => $this->input->post('last_name'),
   'email_address' => $this->input->post('email_address'),
   'username' => $this->input->post('username'),
   'password' => md5($this->input->post('password'))  //make sure password is md5 or same in db
   );
  
   $insert = $this->db->insert('membership', $new_member_insert_data); //insert (insert is new_member_insert_data array) into membership table
   return $insert;
  }
  function retrieve()
   {
    $q = $this->db->get('membership');
    $this->db->where('email_address', $this->input->post('email_address'));  //validate username
    if($q->num_rows() > 0) {
     foreach($q->result() as $row) {
      $data[] = $row;
     }
     return $data;
    }
  

    
  }

}


/*if($q->num_rows() > 0) {
     foreach ($q->result() as $row) {
      $data[] = $row->row;    
    }
    return $data;
   }*/

Here is my controller
Code:
<?php

class Site extends CI_Controller
{
function __construct()
{
  parent::__construct();
  $this->is_logged_in();
}

function members_area()
{
  $this->load->model('Membership_model');
  $data['records'] = $this->Membership_model->retrieve();
  
  //$data['t'] = $this->db->get('membership','first_name');    //Need to have result before converting to a string.
  $this->load->view('logged_in_area', $data);
  
  
}
function account()
{
  redirect('site/members_area');
}

function another_page() // just for sample
{
  echo 'good. you\'re logged in.';
}

function is_logged_in()
{
  $is_logged_in = $this->session->userdata('is_logged_in');
  if(!isset($is_logged_in) || $is_logged_in != true)
  {
   echo 'You don\'t have permission to access this page.';
   echo anchor('login/index', 'Login');
   die();  
   //$this->load->view('login_form');
  }  
}

}

Here is my view
Code:
<!DOCTYPE html>

&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
&lt;title&gt;untitled&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<h2>Welcome Back, &lt;?php echo $this->session->userdata('username'); ?&gt;!</h2>
     <p>If you are a member you can stay. If not, then get out!</p>
    
<h4>
  &lt;?php echo anchor('site/members_area','Profile');?&gt; |
  &lt;?php echo anchor('login/logout', 'Logout');?&gt; |
  &lt;?php echo anchor('site/account', 'Account');?&gt;
  
</h4>



&lt;?php
foreach($records as $row):
  echo $row->first_name;

  ?&gt;

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


Messages In This Thread
Parse error: syntax error, unexpected $end caused by foreach in view - by El Forum - 05-28-2012, 03:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB