This is the error message found on google chrome:
POST http://localhost/display/register/registerUser 500 (Internal Server Error)
My project file name is "display".
One controller file named "register" ,it has a function called "registerUser". All it does is getting user's input, and compare it with database to see if the name is used or not, if valid store it into database and give them a success message, if not valid give a error message.
$username=$this->input->post('name');
$password=$this->input->post('password');
$result=$this->user->checkExistUser($username);
if(!$result){
$data=array(
'username'=>$username,
'password'=>md5($password)
);
$this->user->register($data);
echo "<script>alert('You have success registered');</script>";
$this->load->view('home_view');
}
else{
echo "<script>alert('Sorry, this email address has been used!');</script>";
$this->load->view('registerView');
}
This is my view file named registerView
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to Stock game</title>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js">
</script>
</head>
<body>
<div id="container">
<h1>Welcome to Stock game!</h1>
<div id="body">
<p>This is the register page</p>
</div>
<div>
<form name="userform" id="userform" >
<input type="text" name="name" placeholder="Name"/>
<input type="text" name="password" placeholder="Password"/>
<button name="submit" value="submit">Register</button>
</form>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('form#userform').on('submit',function(e){
e.preventDefault();
var name=$("#name").val();
var password=$("#password").val();
$.ajax({
type:'POST',
url:'register/registerUser',
data:
{'name':JSON.stringify(name),'password':JSON.stringify(password)},
dataType:'JSON',
success: function(response){
if(response=="success"){
alert("Yes login");
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(xhr.responseText);
alert(thrownError);
}
});
});
});
</script>
</div>
<br/>
</body>
</html>
I have tested the controller and model class with a simple form post(form action=xxx, method=post) and it is no error. I searched almost every stackoverflow questions about this, but i still cannot fix it, I hope someone can help me.