We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    How to use the $modx->db->insert() API function? What kind of array does it want? After fighting with it for hours, I finally gave up and did a simple $modx->db->query() with the following:
    $sql = "INSERT INTO modx_subscribers SET
        intTransID = '".$transID."',
        strCustomer = '".$customer."',
        strEmail = '".$email."'";

    A fourth field is not filled; it could be filled with the "DEFAULT" keyword.

    I would really like to know how to get this to work using the API insert function.
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 11975
      • 2,542 Posts
      Hi Susan,

      here a piece of code I’m using

      		$tbCk = $modx->getFullTableName('site_htmlsnippets');
      		$fields['name'] = $chunkName;
      		$fields['description'] = $chunkName;
      		$fields['category'] = $category;
      		$fields['snippet'] = addslashes($chunkContent);
      		$fields['locked'] = 1;
      		//print_r($fields);
      		if($rs = $modx->db->insert($fields,$tbCk)){
      		$logInfo = $chunkName ." installed succesfully !<br>";
      		}else{
      		$logInfo = "error installing => ".chunkName."<br>";
      		}
      	
      


      hope thats helps

      :-)
        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        That did the trick! Thank you! (should be added to the Wiki, the DBAPI page for the insert function is empty)
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org