Codeigniter运行SQL查询后加载空白页

时间:2014-12-17 19:23:58

标签: php mysql database codeigniter

出于某种原因,当我运行SQL查询时,codeigniter将不会加载视图并且只返回一个空白页面,尽管当我通过phpmyadmin手动检查时,查询看起来确实完美。

这是我完整的控制器:

<?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>'; 
}
   }
}
 ?>

这是完整的模型:

<?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();

 }

 }
?>

更多详情: 所有错误检查都已打开,我没有收到任何错误。

添加我的功能后:

   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();
    }

控制器中的呼叫:

$this->registerpagemodel->CreateRep();

这开始发生在我身上,查询将在我对PHPMyAdmin进行双重检查时起作用,但之后视图不会加载,这让我完全陷入困境。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

一切正常,只要看看你的javascipt代码! 您在javascript中的字符串中不能有ENTERED行。用以下代码替换你的js代码:

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

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

我删除了新行,但您可以在js

中的字符串之间使用"" + \n(Enter) ""