CodeIgniter Forums

Full Version: Saving data to MYSQL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have followed an online guide how to do this. But its not working. I've made some slight changes but nothing is working, help

User inputs info page:

<fieldset class="col-xs-12 col-sm-6 personal-info-wrapper">
                        <input type="hidden" id="user-id">
                        <form method="post">
                            <div class="form-group">
                                <label for="postcode">Enter Postcode Area</label>
                                <input style="font-size:12px" name="postCode" id="postcode" class="form-control required" value="e.g CF11">
                             <div class="form-group">
                                <label for="deliveryCost">Delivery Charge</label>
                                <input style="font-size:12px" name="delivery" id="deliveryCost" class="form-control required" value="e.g 5.00">
                            <button type="button" class="save-settings btn btn-primary btn-xs"
                                title="<?= lang('save') ?>">
                                <span class="glyphicon glyphicon-floppy-disk"></span>
                                <?= lang('save') ?>
                            <input type="submit" name="savePostcode" value="Save Data"/>


    /*load database libray manually
    $this->load->database();       */

    /*load Model
    $this->load->model('Settings_model');   */


    public function savedata()
        /*load registration view form*/

        /*Check submit button */


        echo "Records Saved Successfully";

    /* Insert postcodes to table*/

    function saverecords($postCode,$delivery)

    $query="insert into Postcodes values('','$postCode','$delivery')";
you need to save the record using an associated array.

PHP Code:
// Controller
public function savedata()
    /*load registration view form*/

    /*Check submit button */
$data = [
            'first_name' => $this->input->post('postCode'),
            'last_name'  => $this->input->post('delivery'),

        echo "Records Saved Successfully";

// Model

/* Insert postcodes to table*/
public function saverecords($data)
    return $this-db->insert('Postcodes'$data);

SEECodeIgniter User Guide - Database Reference -> Query Builder Class