0

when ever I try to enter double quotes into the table, it shows some db error. I tried with stripslashes and mysql_real_escape_string, but it fails to enter into the table.

Controller

function ConfirmOrder($arr) {
    $confirmation_number = substr(number_format(time() * rand(),0,'',''),0,10); 
    $ord_no = substr(number_format(time() * rand(),0,'',''),0,2); 
    $this->load->model('users_model');
    $this->users_model->ConfirmOrder($arr,$arr['order_id'],$confirmation_number,$ord_no);
    $confirm_status = array('status' => 'true', 'message' => 'Order Confirmed Successfully');

    echo json_encode($confirm_status);
}

Model

function ConfirmOrder($arr,$order_id,$confirmation_no,$ord_no) {
    $data = array(
        'order_number'        => $ord_no.strtotime(date("Y-m-d H:i:s")),
        'order_date'          =>  date("Y-m-d H:i:s"),
        'confirmation_number' =>  $confirmation_no
    );

    $this->db->where('order_id',$order_id);
    $this->db->update('mun_order_master',$data);

    if($arr['my_picks']) {
        $pick_name =  mysql_real_escape_string($arr['pick_name']);

        $data1 = array(
            'user_id'   => $arr['user_id'],
            'order_id'  => $order_id,
            'pick_name' => $pick_name,
            'add_date'  =>  date("Y-m-d H:i:s")
        );

        $this->db->insert('mun_my_picks', $data1);
        return $this->db->insert_id();
    }

    return true;
}

The JSON I use

$json='{"function":"ConfirmOrder","parameters": "order_id": "7","user_id": "25","pick_name": "SPick","my_picks": "Y"},"token":""}'; 
Dushyant Joshi
  • 3,672
  • 3
  • 28
  • 52
Deva
  • 3
  • 4
  • 1
    what is the error you're getting? – Dragony Apr 11 '14 at 07:28
  • Are you using Codeigniter? This is not the right way to insert data *(Codeigniter escapes for you)* – MacMac Apr 11 '14 at 07:29
  • yes i am using codeigniter – Deva Apr 11 '14 at 07:31
  • you are `CI` framework, then no need worried about quote `"` in database, CI library automatic escapes double quote, don't use `mysql_real_escape_string` function – Girish Apr 11 '14 at 07:31
  • See this: http://stackoverflow.com/a/60496/89435 – mavroprovato Apr 11 '14 at 07:31
  • 1
    please share the error you are getting – Shijin TR Apr 11 '14 at 07:31
  • You are probably inserting with missing required columns, please explain *"it shows some db error"* – MacMac Apr 11 '14 at 07:34
  • Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /var/www/html/munch/application/controllers/client.php on line 25 – Deva Apr 11 '14 at 07:35
  • That's not a database error - that's a PHP error. Please paste the `clients.php` code. – MacMac Apr 11 '14 at 07:51
  • hi this is a method executed by using json. I can't test this case in client.php. when testing it leads to php error.it s the backend wrk of an iphone app – Deva Apr 11 '14 at 08:04
  • That's fine, just need to see the source code of `clients.php`... – MacMac Apr 11 '14 at 08:13
  • function ConfirmOrder($arr) { $confirmation_number = substr(number_format(time() * rand(),0,'',''),0,10); $ord_no = substr(number_format(time() * rand(),0,'',''),0,2); $this->load->model('users_model'); $this->users_model->ConfirmOrder($arr,$arr['order_id'],$confirmation_number,$ord_no); }the first code is included in model – Deva Apr 11 '14 at 08:18
  • Please edit your question with the **full** paste, not a portion of it. – MacMac Apr 11 '14 at 08:29
  • @BurningtheCodeigniter can u please check the code – Deva Apr 11 '14 at 10:34
  • You still did not paste the **ENTIRE** code, because I can't check line 25 on the `clients.php`...! Copy it from the top to bottom. – MacMac Apr 11 '14 at 11:02

0 Answers0