Data not added to database

data not inserting into mysql database php
cannot insert data into mysql database php
sql command insert is working but the data not appear in table
unable to insert data in mysql using php
mysql not inserting data
cannot insert data into database
cannot insert data into sql table
error while inserting data into database

been trying to solve what the problem is regarding my code. Haven't had programmed codeigniter for a long time. When I click the ADD ITEM BUTTON, it just stays on the same page and nothing is happening.. Here is my view and model function:

View:

    <form action="<?php echo base_url().'item/addItem' ?> " method="post">

                    <div class="form-group">
                        <label>Name of Patient</label>
                        <input type="name" class="form-control" name="patient_name" placeholder="Name Here" value="<?php echo set_value('patient_name'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Age</label>
                        <input type="input" class="form-control" name="age" placeholder="Age Here" value="<?php echo set_value('age'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Date</label>
                        <input type="date" class="form-control" name="date" placeholder="Date" value="<?php echo set_value('date'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Grade/PD</label>
                        <input type="input" class="form-control" name="grade" placeholder="Grade/PD Here" value="<?php echo set_value('grade'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Frame No.</label>
                        <input type="input" class="form-control" name="frame_no" placeholder="Frame No. Here" value="<?php echo set_value('frame_no'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Frame Amount</label>
                        <input type="input" class="form-control" name="frame_amo" placeholder="Frame Amount Here" value="<?php echo set_value('frame_amo'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Lens Type/Amount</label>
                        <input type="input" class="form-control" name="lens_typeamo" placeholder="Lens Type/Amount Here" value="<?php echo set_value('lens_typeamo'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Laboratory</label>
                        <input type="input" class="form-control" name="labo" placeholder="Laboratory Here" value="<?php echo set_value('labo'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Total Amount</label>
                        <input type="input" class="form-control" name="total" placeholder="Total Amount Here" value="<?php echo set_value('total'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Saleslady</label>
                        <input type="input" class="form-control" name="saleslady" placeholder="Saleslady Name Here" value="<?php echo set_value('saleslady'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Doctor</label>
                        <input type="input" class="form-control" name="doctor" placeholder="Doctor Name Here" value="<?php echo set_value('doctor'); ?>">
                    </div>


                    <a href="<?php echo base_url().'item/itemlistadmin'?>" class="btn btn-info " role="button"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> BACK </a>
                    <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> ADD ITEM</button>
                </form>

I'm not sure if what i typed in this area are correct :C

Model:

    public function addItem(){

        $patient_name = $this->input->post('patient_name');
        $age = $this->input->post('age');
        $date = $this->input->post('date');
        $grade = $this->input->post('grade');
        $frame_no = $this->input->post('frame_no');
        $frame_amo = $this->input->post('frame_amo');
        $lens_typeamo = $this->input->post('lens_typeamo');
        $labo = $this->input->post('labo');
        $total = $this->input->post('total');                       
        $saleslady = $this->input->post('saleslady');
        $doctor = $this->input->post('doctor'); 


        $item = array(
            'px_name' => $patient_name,
            'px_age' => $age,
            'px_date' => $date,
            'px_grade' => $grade,
            'px_frame_no' => $frame_no,
            'px_frame_amo' => $frame_amo,
            'px_lens_typeamo' => $lens_typeamo,
            'px_labo' => $labo,
            'px_total' => $total,
            'px_saleslady' => $saleslady,
            'px_doctor' => $doctor
        );

    $this->db->insert('tblitem',$item);

}

Here is my database:

see here not sure what to change anymore :'< please help. Thanks!

it's should be

Controller :

public function addItem() {

    $patient_name = $this->input->post('patient_name');
    $age = $this->input->post('age');
    $date = $this->input->post('date');
    $grade = $this->input->post('grade');
    $frame_no = $this->input->post('frame_no');
    $frame_amo = $this->input->post('frame_amo');
    $lens_typeamo = $this->input->post('lens_typeamo');
    $labo = $this->input->post('labo');
    $total = $this->input->post('total');
    $saleslady = $this->input->post('saleslady');
    $doctor = $this->input->post('doctor');

    $item = array(
        'px_name' => $patient_name,
        'px_age' => $age,
        'px_date' => $date,
        'px_grade' => $grade,
        'px_frame_no' => $frame_no,
        'px_frame_amo' => $frame_amo,
        'px_lens_typeamo' => $lens_typeamo,
        'px_labo' => $labo,
        'px_total' => $total,
        'px_saleslady' => $saleslady,
        'px_doctor' => $doctor
    );

    $this->db->insert($item);
}

Model :

public function insert($item)
{
  $this->db->insert('tblitem', $data);
}

Why can't insert data into the database? - PHP, the html file <form method="post" action="add.php"> <input USER_NAME, PASSWORD ) or die('Cannot connect to the database because:  So you won't see any changes persisted to the database. Actually, if the database file in the project is marked as "Copy if newer" then it will only overwrite the copy in the Debug folder if you make changes to the database structure. Also, the changes you make while running the program are written to the copy of your DB in the ..\bin\Debug folder.

Try this:

controller

    public function addItem()
    {
    $item=array(  
        'patient_name' = $this->input->post('patient_name'),
        'age' = $this->input->post('age'),
        'date' = $this->input->post('date'),
        'grade' = $this->input->post('grade'),
        'frame_no' = $this->input->post('frame_no'),
        'frame_amo' = $this->input->post('frame_amo'),
        'lens_typeamo' = $this->input->post('lens_typeamo'),
        'labo' = $this->input->post('labo'),
        'total' = $this->input->post('total'),
        'saleslady' = $this->input->post('saleslady'),
        'doctor' = $this->input->post('doctor'),     
        );
        $this->ModelName->addItem($item); 
    }

model

    public function addItem($item)
    {  
    $this->db->insert('tblitem', $item);
    $this->db->update('users');
    }

HTML Form is not adding data to MySQL database? - PHP, I am writing PHP code where I am trying to insert user data from an HTML form into a MySQL database for recording attendance. The problem  That explains how to make your database world readable/writeable again. the authentication from the Firebase 2.x SDK will not work against projects created on the new Firebase console. So #1 may be a good quick workaround, but you really should take an updated tutorial, such as the ones suggested in other answers.

controller's code : public function add_item()

{

$data=array(

'patient_name' = $this->input->post('patient_name'),

'age' = $this->input->post('age'),

'date' = $this->input->post('date'),

'grade' = $this->input->post('grade'),

'frame_no' = $this->input->post('frame_no'),

'frame_amo' = $this->input->post('frame_amo'),

'lens_typeamo' = $this->input->post('lens_typeamo'),

'labo' = $this->input->post('labo'),

'total' = $this->input->post('total'),

'saleslady' = $this->input->post('saleslady'),

'doctor' = $this->input->post('doctor'),

);

$this>load->model('model_name');

$this->model_name->add_item($data);

}

  model's code :

  public function add_item($data){

$this->db->insert('table_name',$data);

}

Dont forget to check the .htaccess file and base_url

Model save using setData and addData not adding to database , This is what you have done here $data = array('appid'=>'new_appid','custid'=>1,'​info'=>'info'); $model = Mage::getModel('interface/data')->setData($data);  To add data or log files to a database. In Object Explorer, connect to an instance of the SQL Server Database Engine and then expand that instance. Expand Databases, right-click the database from which to add the files, and then click Properties. In the Database Properties dialog box, select the Files page.

How to Use PHP to Insert Data Into MySQL Database, We will not go through this part again, however, if you wish to know what each line In this example, we are adding data to the table Students. If your application doesn't use TableAdapters, you can use command objects (for example, SqlCommand) to insert new records in your database. If your application uses datasets to store data, use the TableAdapter.Update method. The Update method sends all changes (updates, inserts, and deletes) to the database.

Working With In-Database Data, in-db data is that changes to the underlying database schema will not automatically be reflected in the Spotfire analysis. This means that if a column is added  If your application never sends those changes back to the data source, then you're finished with the update. If you do send the changes back to the database, a second step is required. If you aren't using data-bound controls, you have to manually call the Update method of the same TableAdapter (or data adapter)

Add a data connection to a Microsoft SQL Server database, You cannot add a secondary data connection to your form template that submits form data to a database. If you want to use a secondary data connection to submit​  PHP Code to INSERT Data Into MySQL Database. There are two methods you can use to INSERT data into your MySQL database. The PHP MySQLi method and PHP Data Object or PDO method. MySQLi Method. First, you’ll need to establish a connection to a database. After that is done, we can proceed with the MySQL query INSERT. Here is a full PHP code

Comments
  • What about controller part as form will be hitting controller function ?
  • can you do a print_r($item); and see whether the array is correct or not ?
  • Replace your model name in the correct name and try the above code for controller and model