Welcome Guest, Not a member yet? Register   Sign In
How Can i Insert data In DataBase
#1

In this Project For inserting Data in database cretaed  basically 3 pages. i m using Wamp Server ..My dataBase Name is "artipick" , table name ="user" and in table 4 Field name  id , username , password , email  .When i will Submit the form Its generate Error..

Plz Reply me..
1)controllers/Register.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Register extends CI_Controller {

public function _construct()
{
parent ::_construct();
$this->load->model(array('mod_user'));
}

/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$email = NULL;
$username = NULL;
$password = NULL;
$submit = NULL;
extract($_POST);
$params['email']=$email;
$params['username']=$username;
$params['password']=$password;
if(isset($submit))
{

$this->mod_user->update($params);
}
$this->load->view('register');
}
}
2)Views/register.php

<ul class="nav navbar-nav navbar-right">
           <li><a href="http://localhost/Artipick/index.php/register">Register</a></li>
           <li class="active"><a href="http://localhost/Artipick/index.php/register">Login <span class="sr-only">(current)</span></a></li></ul>

<form action="register" method="POST">
<input type="text" name="email" placeholder="Email Id" /><br/>
<input type="text" name="username" placeholder="User Name" /><br/>
<input type="text" name="password" placeholder="Password" /><br/>
<button type="submit" name="submit" value="save">Save</button>
</form>
3)Models/Mod_user.php


<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Mod_user extends CI_Model {
protected $table= 'user';
function _construct()
{
parent ::_construtct();
}
public function update($params)
{
$fields = array(
'email' => $params['email'],
'username' => $params['username'],
'password' => $params['password']
);
$this->db->insert($this->table , $fields);
}

}

Attached Files Thumbnail(s)
   
Reply
#2

First, don't use extract() on $_POST, there's even a warning on the manual page telling you not to do that. So, in your controller's index() method, do something like this:

PHP Code:
$username $this->input->post('username');
$email $this->input->post('email');
$password $this->input->post('password'); 

It's a little confusing for your model to have an update method which just performs an insert, but I'll assume that you're simplifying your code.

Second, you need to protect the password, not just insert it into your database. So, before inserting the data, you should use PHP's password_hash() function. Then, when you need to verify the password for user login, you'll have to use the password_verify() function.
Reply
#3

(10-16-2015, 06:07 AM)viveksoftcomp Wrote: In this Project For inserting Data in database cretaed  basically 3 pages. i m using Wamp Server ..My dataBase Name is "artipick" , table name ="user" and in table 4 Field name  id , username , password , email  .When i will Submit the form Its generate Error..

Plz Reply me..
1)controllers/Register.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Register extends CI_Controller {

public function _construct()
{
parent ::_construct();
$this->load->model(array('mod_user'));
}

You've missed one underscore in constructor name. It should be __construct()
Reply




Theme © iAndrew 2016 - Forum software by © MyBB