• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving data to MYSQL

#1
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:


Code:
<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>
                             <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">
                            </div>
                            <button type="button" class="save-settings btn btn-primary btn-xs"
                                title="<?= lang('save') ?>">
                                <span class="glyphicon glyphicon-floppy-disk"></span>
                                <?= lang('save') ?>
                            </button>
                            <input type="submit" name="savePostcode" value="Save Data"/>
                        </form>

</fieldset>


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

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


    }

    public function savedata()
    {
        /*load registration view form*/
        $this->load->view('insert');

        /*Check submit button */
        if($this->input->post('savePostcode'))
        {

        $first_name=$this->input->post('postCode');
        $last_name=$this->input->post('delivery');

        $this->Settings_model->saverecords($postCode,$delivery);
        echo "Records Saved Successfully";
        }
    }

Model
Code:
    /* Insert postcodes to table*/

    function saverecords($postCode,$delivery)
    {

    $query="insert into Postcodes values('','$postCode','$delivery')";
    $this->db->query($query);
    }
Reply

#2
you need to save the record using an associated array.

PHP Code:
// Controller
public function savedata()
{
    /*load registration view form*/
    $this->load->view('insert');

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

        $this->Settings_model->saverecords($data);
        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
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.