ddrossi93
ddrossi93

Reputation: 385

Codeigniter Controller function won't echo string

I am trying to display a string when the code enters an if statement.

I double checked and the code does go into the statement, but nothing prints.

Here is my controller function:

public function clock_in()
{

    $this->load->model('model_users');


       $this->db->where('USER_EMAIL', $this->session->userdata('USER_EMAIL'));

    $query = $this->db->get('clocked_in_users');

    if($query->num_rows() == 1){



         echo "Already Clocked in";
        exit;

    }else{

    $this->model_users->clock_user_in();
    };



    redirect('main/members');




}

and my view:

<!DOCTYPE html>
<html lang="en">

<body>

<div class="container">

    <h1>Members</h1>






    <?php


        echo "<pre>";
        print_r ($this->session->all_userdata()); //displays all user session data.
        echo "</pre>";

        $this->load->helper('date');

        echo "<h2>";

        echo $date = date('Y-m-d H:i:s');

        echo "</h2>";

    ?>


    <a href="<?php echo 'clock_in'?>">Clock In</a>

    <!-- clock in button -->

       <br />
    <br />

      <a href="<?php echo 'clock_out'?>">Clock Out</a>
    <br />        
    <br />
    <a href="<?php echo 'main/logout'?>">Logout</a> <!-- logout button. shit acts weird when you use it-->




</div>


</body>

</html>

I'm not sure what I am doing wrong. Every other echo in my controller will work find, but not this one. Any advice is appreciated.

EDIT: Problem has been fixed, thanks to Arsalan. I had to add exit; after the echo to make sure it displays before it reloads the members view

Upvotes: 0

Views: 7264

Answers (1)

Arsalan
Arsalan

Reputation: 471

You need to put exit; after echo "Already Clocked in"; if you want to make sure the conditions sets true.. since redirect('main/members'); redirects it to view and it wont print.

Upvotes: 6

Related Questions