Thursday, November 5
Trending
- 12 Best Web Application Firewalls (WAF) for 2027
- Best Ethical Hacking Tools in 2027: Free & Paid Picks
- Software supply chain attacks 2026: Timeline and developer checklist
- Binance Hack: $6.3 Billion Drained in the Largest Crypto Theft Ever. What We Know So Far
- This Site Uses XSLT Chrome Warning Explained: How to Fix It
- iPad mini OLED Price in India: Wi-Fi & Cellular Variants, Offers
- iMac M6 Price in India: All Variants, Colors, Offers and Release Date
- MacBook Pro M6 Price in India
In this article, we will discuss, How to create a Sign up with MySQL database using the CodeIgniter 3.
1. Create a controller file Signup.php in the applications/controllers/ directory.
class Signup extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('signup_model');
}
public function sign_up() {
$this->load->view(‘sign_up’);
}
public function register() {
$name = $this->input->post('name');
$email = $this->input->post('email');
$password = $this->input->post('pass');
$phone = $this->input->post('phone');
$data = [
‘name’ => $name,
‘email’ => $email,
‘password’ => $password,
‘phone’ => $phone,
];
$result = $this->signup_model->is_user_exists($email);
if(!$result) {
$user = $this->signup_model->add($data);
if($user) {
echo “Your account created successfully”;
} else {
echo “Something went wrong.”;
}
} else {
echo “User is already exists.”;
}
}
}2. Create a model file Signin_model.php in the applications/models/ directory.
class Signup_model extends CI_Model {
public function add($data) {
return $this->db->insert(‘user_info’, $data);
}
public function is_user_exists($email) {
$this->db->where([‘email’ => $email]);
$query = $this->db->get(‘user_info’);
return $query->num_rows();
}
}3. Create a sign_up.php file in the applications/views/ directory.
<form method="post"
action="<?php echo base_url('user/register') ?>">
<table width="600" align="center"
border="1" cellspacing="5" cellpadding="5">
<tr>
<td colspan="2">
<?php echo $error; ?>
</td>
</tr>
<tr>
<td width="230">Enter Your Name</td>
<td width="329">
<input type="text" name="name" />
</td>
</tr>
<tr>
<td>Enter Your Email</td>
<td>
<input type="text" name="email" />
</td>
</tr>
<tr>
<td>Enter Your Mobile</td>
<td>
<input type="text" name="phone" />
</td>
</tr>
<tr>
<td>Enter Your Password</td>
<td>
<input type="password" name="pass" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="save"
value="Register" />
</td>
</tr>
</table>
</form>


