-3

So that we're on the same page, I'm following along with this tutorial:

http://www.kodingmadesimple.com/2015/08/create-simple-registration-form-codeigniter-email-verification.html

Besides the starting CodeIgniter files, above is exactly what my code looks like. But here it is for those who can't view the link:

I have the model:

<?php
class user_model extends CI_Model
{
function __construct()
{
    // Call the Model constructor
    parent::__construct();
}

//insert into user table
function insertUser($data)
{
    return $this->db->insert('user', $data);
}

//send verification email to user's email id
function sendEmail($to_email)
{
    $from_email = 'team@mydomain.com'; //change this to yours
    $subject = 'Verify Your Email Address';
    $message = 'Dear User,<br /><br />Please click on the below activation link to verify your email address.<br /><br /> http://www.example.com/user/verify/' . md5($to_email) . '<br /><br /><br />Thanks<br />Mydomain Team';

    //configure email settings
    $config['protocol'] = 'smtp';
    $config['smtp_host'] = 'ssl://smtp.mydomain.com'; //smtp host name
    $config['smtp_port'] = '465'; //smtp port number
    $config['smtp_user'] = $from_email;
    $config['smtp_pass'] = '********'; //$from_email password
    $config['mailtype'] = 'html';
    $config['charset'] = 'iso-8859-1';
    $config['wordwrap'] = TRUE;
    $config['newline'] = "\r\n"; //use double quotes
    $this->email->initialize($config);

    //send mail
    $this->email->from($from_email, 'Mydomain');
    $this->email->to($to_email);
    $this->email->subject($subject);
    $this->email->message($message);
    return $this->email->send();
}

//activate user account
function verifyEmailID($key)
{
    $data = array('status' => 1);
    $this->db->where('md5(email)', $key);
    return $this->db->update('user', $data);
}
}
?>

The Controller:

 <?php
 class user extends CI_Controller
 {
public function __construct()
{
    parent::__construct();
    $this->load->helper(array('form','url'));
    $this->load->library(array('session', 'form_validation', 'email'));
    $this->load->database();
    $this->load->model('user_model');
}

function index()
{
    $this->register();
}

function register()
{
    //set validation rules
    $this->form_validation->set_rules('fname', 'First Name', 'trim|required|alpha|min_length[3]|max_length[30]|xss_clean');
    $this->form_validation->set_rules('lname', 'Last Name', 'trim|required|alpha|min_length[3]|max_length[30]|xss_clean');
    $this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email|is_unique[user.email]');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|matches[cpassword]|md5');
    $this->form_validation->set_rules('cpassword', 'Confirm Password', 'trim|required');

    //validate form input
    if ($this->form_validation->run() == FALSE)
    {
        // fails
        $this->load->view('user_registration_view');
    }
    else
    {
        //insert the user registration details into database
        $data = array(
            'fname' => $this->input->post('fname'),
            'lname' => $this->input->post('lname'),
            'email' => $this->input->post('email'),
            'password' => $this->input->post('password')
        );

        // insert form data into database
        if ($this->user_model->insertUser($data))
        {
            // send email
            if ($this->user_model->sendEmail($this->input->post('email')))
            {
                // successfully sent mail
                $this->session->set_flashdata('msg','<div class="alert alert-success text-center">You are Successfully Registered! Please confirm the mail sent to your Email-ID!!!</div>');
                redirect('user/register');
            }
            else
            {
                // error
                $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error.  Please try again later!!!</div>');
                redirect('user/register');
            }
        }
        else
        {
            // error
            $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error.  Please try again later!!!</div>');
            redirect('user/register');
        }
    }
}

function verify($hash=NULL)
{
    if ($this->user_model->verifyEmailID($hash))
    {
        $this->session->set_flashdata('verify_msg','<div class="alert alert-success text-center">Your Email Address is successfully verified! Please login to access your account!</div>');
        redirect('user/register');
    }
    else
    {
        $this->session->set_flashdata('verify_msg','<div class="alert alert-danger text-center">Sorry! There is error verifying your Email Address!</div>');
        redirect('user/register');
         }
     }
 }
 ?>

And the View:

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CodeIgniter User Registration Form Demo</title>
    <link href="<?php echo base_url("bootstrap/css/bootstrap.css"); ?>" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
<div class="row">
    <div class="col-md-6 col-md-offset-3">
        <?php echo $this->session->flashdata('verify_msg'); ?>
    </div>
</div>

<div class="row">
    <div class="col-md-6 col-md-offset-3">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4>User Registration Form</h4>
            </div>
            <div class="panel-body">
                <?php $attributes = array("name" => "registrationform");
                echo form_open("user/register", $attributes);?>
                <div class="form-group">
                    <label for="name">First Name</label>
                    <input class="form-control" name="fname" placeholder="Your First Name" type="text" value="<?php echo set_value('fname'); ?>" />
                    <span class="text-danger"><?php echo form_error('fname'); ?></span>
                </div>

                <div class="form-group">
                    <label for="name">Last Name</label>
                    <input class="form-control" name="lname" placeholder="Last Name" type="text" value="<?php echo set_value('lname'); ?>" />
                    <span class="text-danger"><?php echo form_error('lname'); ?></span>
                </div>

                <div class="form-group">
                    <label for="email">Email ID</label>
                    <input class="form-control" name="email" placeholder="Email-ID" type="text" value="<?php echo set_value('email'); ?>" />
                    <span class="text-danger"><?php echo form_error('email'); ?></span>
                </div>

                <div class="form-group">
                    <label for="subject">Password</label>
                    <input class="form-control" name="password" placeholder="Password" type="password" />
                    <span class="text-danger"><?php echo form_error('password'); ?></span>
                </div>

                <div class="form-group">
                    <label for="subject">Confirm Password</label>
                    <input class="form-control" name="cpassword" placeholder="Confirm Password" type="password" />
                    <span class="text-danger"><?php echo form_error('cpassword'); ?></span>
                </div>

                <div class="form-group">
                    <button name="submit" type="submit" class="btn btn-default">Signup</button>
                    <button name="cancel" type="reset" class="btn btn-default">Cancel</button>
                </div>
                <?php echo form_close(); ?>
                <?php echo $this->session->flashdata('msg'); ?>
            </div>
        </div>
    </div>
</div>
</div>
</body>

I've set up my database in mySQL and my form comes out just fine when connecting to my local server.

But upon filling out the form and hitting "Sign Up" I hit this error in Safari:

https://i.stack.imgur.com/zbhL9.png

Any idea what could be causing this and how to fix it?

Rumiko
  • 1
  • 1
  • 4
  • 1
    Show the relevant code within your OP; do not expect us to click on the link and make guesses about what *"basically"* is supposed to mean. Your question will also not remain helpful to others when the link goes dead. – Sparky Feb 08 '16 at 23:11
  • what is the actual `action` url in your form as you see it in browser? How are you creating that `action` – charlietfl Feb 08 '16 at 23:13
  • Sorry about that Sparky. "Basically" wasn't the right choice of word. My code looks exactly as the code does in the tutorial. I will edit the code into my post shortly. – Rumiko Feb 08 '16 at 23:35
  • Alright, it's all edited now. – Rumiko Feb 09 '16 at 00:27

1 Answers1

0

If your using codeigniter 3

You have your base url blank and that is why ::1 you can leave it blank will work most of the time but you may run it to error.

$config['base_url'] = '';

Set your base url.

$config['base_url'] = 'http://localhost/project/';

Or A Live Domain Example

$config['base_url'] = 'http://www.example.com/';

Update:

Check your controllers etc make sure your file name has first letter upper case and same with class. Example: User.php and class User extends CI_Controller {}

  • CodeIgniter is supposed to work fine with a blank `base_url` setting... it will auto-detect since version 2. See: http://stackoverflow.com/a/11792342/594235 – Sparky Feb 08 '16 at 23:13
  • @Sparky On Codeigniter 3 will run in to some issue some times. As other people have had problems. –  Feb 08 '16 at 23:15
  • I set the base_url to http://localhost:8888/myProjectFolder/ ( – Rumiko Feb 09 '16 at 00:58
  • @wolfgang1983 Thank you. I tried it, but to no avail. However, I think I have an idea of why i'm getting the 404. I put "http://localhost:8888/myProjectFolder/" for my base_url, though my 404 says "The requested URL /myProjectFolder/index.php/User/register was not found on this server." Index.php is just the Index File set by Code Igniter by default. But I'm not sure what User/register is. I know where it came from though. It's in the view: "registrationform"); echo form_open("user/register", $attributes);?> But I don't know what it's trying to acces – Rumiko Feb 09 '16 at 17:24
  • @Rumiko first off in your url I would use lower case second make sure your user file name is User.php and also you may need to set routes.php http://www.codeigniter.com/user_guide/general/routing.html –  Feb 09 '16 at 23:19
  • @wolfgang1983 After all of that the User.php file was incorrectly named. I'm all set now. Thanks man. – Rumiko Feb 10 '16 at 17:34
  • @wolfgang1983 Ok. The check is green. Is that how you accept it? If so, it's all set. Thanks again! – Rumiko Feb 11 '16 at 21:17