VIEWS
<div id="result_post_wifi"></div>
<form role="form" action="" id="form-registrasi-field" class="form-registrasi" onsubmit="return registration();">
<div class="form-group">
<label class="sr-only" for="form-username">Username</label>
<input type="text" name="username" placeholder="Username..." class="form-username form-control" id="username" required>
</div>
<div class="form-group">
<label class="sr-only" for="form-password">Password</label>
<input type="password" name="password" placeholder="Password..." class="form-password form-control" id="password" required>
</div>
<div class="form-group">
<label class="sr-only" for="form-password2">Password</label>
<input type="password" name="password2" placeholder="Confirm Password..." class="form-password2 form-control" id="password_lagi" required>
</div>
<div class="form-group">
<label class="sr-only" for="form-name">Full Name</label>
<input type="text" name="name" placeholder="Full Name..." class="form-name form-control" id="name" required>
</div>
<div class="form-group">
<label class="sr-only" for="form-email">Email</label>
<input type="text" name="email" placeholder="Email..." class="form-email form-control" id="email" required>
</div>
<button type="submit" class="btn"> REGISTRASI </button>
</form>
</div>
</div>
</div>
JQUERY SCRIPT
function open_form()
{
$('#result_wifi').attr({style : 'display:none'});
$('#form_wifi').removeAttr('style');
}
function registration()
{
$('#result_post_wifi').html('<div class="alert alert-info">Sending Data ...</div>');
$.ajax({
dataType : "json",
type : "POST",
url : "wifi/wifi_sign_up",
data : "username=" + $('#username').val() +
"&password=" + $('#password').val() +
"&password2=" + $('#password2').val() +
"&name=" + $('#name').val() +
"&email=" + $('#email').val() +
success : function(res)
{
$('#result_post_wifi').html(res.message);
if(res.status == '200')
{
$('#username').val('');
$('#password').val('');
$('#password2').val('');
$('#name').val('');
$('#email').val('');
$('#form_registrasi_field').attr({style : 'display:none'});
}
},
error : function(){ $('#result_post_wifi').html('<div class="alert alert-warning">Fail to send registration form.</div>'); },
timeout: 50000
});
return false;
}
CONTROLLER
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Wifi extends MX_Controller {
public function __construct()
{
parent::__construct();
// $this->load->model('wifi_model');
}
public function sign_up()
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$password2 = $this->input->post('password2');
$name = $this->input->post('name');
$email = $this->input->post('email');
$this->wifi_model->add_user();
header("Content-type: application/json");
echo "{\"data\":" .json_encode($data). "}";
MODELS
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Wifi_model extends MX_Model {
public function __construct()
{
parent::__construct();
}
public function add_user($data)
{
$data=array(
'username'=>$this->input->post('username'),
'password'=>md5($this->input->post('password')),
'password2'=>md5($this->input->post('password2')),
'name'=>$this->input->post('name'),
'email'=>$this->input->post('email'),
);
$this->db->insert('wifi_regs', $data);
the above code still doesn't want to insert to the mysql database.
i've been trying with some other way but it still doesn't works