2

Magento Enterprise 1.14.0.1

I have a plugin that I am altering the IndexController file for so that it will insert data collected from a user into a database table I created.

So basically I altered the Magento database to have new table which I am calling sample_requests. My issue is that when the IndexController is fired nothing is being inserted into the database. All database columns are Varchar(255) with the exception of the request_date column which is a datetime column type.

below is my code which I have in the IndexController.php file

    $personal_name = 'test';
    $customer_email = 'boo';
    //Open Database Conenction
      $resource = Mage::getSingleton('core/resource');
      $writeConnection = $resource->getConnection('core_write');

      //The Query
        $query = "insert into magento.sample_requests
                       (first_name, last_name, email_addr, address, city, state, zip, country, customeri_id, request_date) 
                  values($personal_name, NULL, $customer_email, sdf, sdf, sdf, sdf, sdf, 0, NOW())";


        $writeConnection->query($query);
2
  • 1
    You should really think about using magento models. Beside this, your code looks ok, are you sure it is called? Commented Jun 11, 2015 at 18:31
  • All that SQL!!! So much easier to use: Mage::getModel('my/model')->load($id)->setMyProperty()->save() Commented Jun 11, 2015 at 19:05

1 Answer 1

4

value must be in ''

 $query = "insert into magento.sample_requests
                       (first_name, last_name, email_addr, address, city, state, zip, country, customeri_id, `request_date`) 
                  values($personal_name,' NULL',$customer_email,'sdf', 'sdf', 'sdf', 'sdf', 'sdf', '0', NOW())";
1
  • Thank you apparently the issue was I didnt have a ' arround each of my values because when I change my query to match Qaisar Satti 's answer it works now. Commented Jun 11, 2015 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.