For some reason, when I run an SQL Query codeigniter won't load the view and just returns a blank page although the query does seem to work perfectly when I check manually through phpmyadmin.
Here is my complete Controller:
<?php
class RegisterPageController extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('registerpagemodel');
$this->load->helper('url');
}
public function index()
{
$this->load->view('RegisterPageView');
}
public function AddUser()
{
$Usrname = $this->input->post('UserName');
$Password = $this->input->post('PWD');
$Email= $this->input->post('Email');
if ($Usrname == null||$Usrname == ''||$Password == null||$Password == ''||$Email ==
null||$Email =='')
{
$this->load->view('RegisterPageView');
/*This is a little script that displays an alert box on screen when a field has been
left blank.*/
echo '<script type="text/javascript">
window.onload = function () { alert("Username, Password or Email Has Been Left Empty, Please Try Again."); }
</script>';
return false;
}
$Check = $this->registerpagemodel->CheckExsistingUser($Usrname);
if ($Check == TRUE){
$this->load->view('RegisterPageView');
/*This is a little script that displays an alert box on screen saying you have been
registered.*/
echo '<script type="text/javascript">
window.onload = function () { alert("Username already Exists, please choose another"); }
</script>';
}
else
{
/*This will call the AddNewUser function from the Model*/
$this->registerpagemodel->AddNewUser($Usrname, $Password, $Email);
$this->registerpagemodel->CreateRep();
$this->load->view('WelcomePageView');
/*This is a little script that displays an alert box on screen saying you have been
registered.*/
echo '<script type="text/javascript">
window.onload = function () { alert("You have been registered"); }
</script>';
}
}
}
?>
And here is the complete model:
<?php
class registerpagemodel extends CI_Model {
function __construct()
{
parent::__construct();
$this->load->database();
}
function AddNewUser($User, $Pass, $Email)
{
/*This will Hash the password with a Salt (New PHP 5.5 Or Above)*/
$Hash = password_hash($Pass, PASSWORD_DEFAULT);
/*This will put the username and hashed password into an array*/
$UsrArray = array(
'Username'=>$User,
'Password'=>$Hash,
'Email'=>$Email);
/*This will put the data in the array into the table using the active record class*/
$this->db->insert('Users', $UsrArray);
}
/*Checks if the username Currently Exsists*/
function CheckExsistingUser ($User)
{
$this->db->where('Username', $User);
if ($this->db->count_all_results('Users') > 0){
$temp = TRUE;
return $temp;
}
else
{
$Pass = FALSE;
return $Pass;
}
}
function CreateRep ()
{
$sql ="INSERT INTO Reputation(Reputation, User_Rep_ID) VALUES (0, (SELECT ID FROM
Users ORDER BY ID DESC LIMIT 1))";
$results = $this->db->query($sql);
//$data = $results->result_array();
$results->free_result();
}
}
?>
More Details: All the error checking is turned on and I am not getting any errors.
After Adding my function:
function CreateRep ()
{
$sql ="INSERT INTO Reputation(Reputation, User_Rep_ID) VALUES (0, (SELECT ID FROM
Users ORDER BY ID DESC LIMIT 1))";
$results = $this->db->query($sql);
//$data = $results->result_array();
$results->free_result();
}
The Call in Controller:
$this->registerpagemodel->CreateRep();
This started happening to me, the query will work as I double check on PHPMyAdmin but the view won't load afterwards and this has left me completely stumped. Any help is much appreciated.