I am quite new to PHP and am following tutorials to insert data into database. Syntax is all running fine, just that typing in data in the form doesn't insert any data into database. I've created out the table, and have checked if the insert query is working correctly in MySQL.
Controller: studCredController
class studCredController extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->database();
//load Model
$this->load->model('studCredModeller');
}
//Register students
public function registerStud() {
//load registration view form
$this->load->view('Home');
//Check the submit button
if($this->input->post('save'))
{
$username = $this -> input -> post('username');
$email = $this -> input -> post('email');
$password = $this -> input -> post('password');
$admin_no = $this -> input -> post('adminNo');
$phone = $this -> input -> post('phone');
//call method of studCredModeller and pass variable as parameter
$this -> studCredModeller -> saveRecords($username, $email, $password, $admin_no, $phone);
echo "Records Saved Successfully";
}
}
}
Model: studCredModeller
class studCredModeller extends CI_Model
{
public function saveRecords($username, $email, $password, $adminNo, $phone);
{
$query="insert into locka.stud_login values('$username','$email','$password','$admin_no','$phone', ' ')";
$this->db->query($query);
}
}
View: Home
<form method="post">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" name="username" placeholder="Username">
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<label>Email</label>
<input type="email" class="form-control" name="email" placeholder="Email">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" name="password" placeholder="Password">
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<label>Admin No</label>
<input type="text" class="form-control" name="adminNo" placeholder="AdminNo">
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<label>Phone number</label>
<input type="number" class="form-control" name="phone" placeholder="Phone">
</div>
</div>
</div>
<input type="submit" value="Submit" name="save" class="btn btn-skin btn-block btn-lg">
<p class="lead-footer">* We'll contact you by phone & email later</p>
</form>
Thank you for looking at the codes. I have been stuck at this for a few days, trying out different tutorials.