• Call Us: +92-333-7276335
  • - Mail Us: info@shekztech.com

Plot 1177, Sector 31B - Crossing, Karachi, Sindh

Create the form in Codeigniter 4 and insert the record

Please Login and enroll in this course to view the lesson.

Create the form in Codeigniter 4 and insert the record

You can create the form using form_helper in Codeigniter 4, In this tutorial, we create the form to insert the record in the database you guys easily understand how to perform  the first operation which is Inserting in Codeigniter 4

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
      content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <form action="<?php echo site_url('students/addstudent'); ?>" method="post">
    <p>Student Name
      <input type="text" name="std" placeholder="Student Name">
    </p>
    <p>Student Subject
      <input type="text" name="subject" placeholder="Student Name">
    </p>
    <button type="submit">Add Student</button>
  </form>
</body>
</html>

This is your Codeigniter 4 model

<?php namespace AppModels;
use CodeIgniterModel;

class MyStudents extends Model
{
  protected $DBGroup = 'default';

  protected $table = 'students';
  protected $primaryKey = 's_id';
  protected $returnType = 'array';
  protected $useTimestamps = true;
  protected $allowedFields = ['s_name','s_date','s_subject','s_update'];
  protected $createdField = 's_date';
  protected $updatedField = 's_update';

}