0

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.

1 Answer 1

0

Everything works okay man , just look at your javascipt code! You CAN NOT have ENTERED line in your string in javascript. replace your js codes by these :

<script type="text/javascript">
    window.onload = function () { alert("Username, Password or Email Has Been Left Empty, Please Try Again."); }
</script>

AND

<script type="text/javascript">
    window.onload = function () { alert("Username already Exists, please choose another"); }
</script>

I removed the new lines , yet you can use "" + \n(Enter) "" between your strings in js

Sign up to request clarification or add additional context in comments.

5 Comments

I tried that and i've just tripled checked after making sure everything is ok with, it's still not solving the problem, maybe it's just the way it formatted on here for that I apologise.
Are you sure ?! I've copied your codes into my own CI and made it work! - Will your new record added into DB?
That's so strange..in mine it just gives a blank page and yes my new record gets added both of them a new user record gets added in my users table and same for the reputation table. If it helps I'm developing on Firefox
Have you firebug? please add new row and turn your firebug on and in console tab , post what are you seeing . and in the blank page show the page source and let me know.
I have just done what you asked, no errors - nothing came up on firebug however blank page source was completely empty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.