<field key="id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="pk" />
(DEBUG) No primary key value found for pk definition: id
$myUser = $xpdo->newObject('myUser'); $myUser->fromArray($fields, '', true);
INSERT INTO `pfp`.`_landlord` (`title`, `first_name`, `last_name`, `email`, `addr1`, `addr2`, `addr3`, `city`, `county`, `country`, `post_code`, `home_phone`, `work_phone`, `mobile`, `fax`, `web_user_id`, `on_mailing_list`) VALUES('title', 'first_name', 'last_name', 'email', 'addr1', 'addr2', 'addr3', 'city', 'county', 'country', 'post_code', 'home_phone', 'work_phone', 'mobile', 'fax', 10, true)
INSERT INTO `pfp`.`_landlord`
INSERT INTO `pfp_landlord`
<?php ... // pre-processing above // use xpdo to insert the user's data into the landlord table include_once ($modx->config['base_path']. 'xpdo/xpdo.class.php'); $xpdo= new xPDO('mysql:host=localhost;dbname=pfp', "username", "password"); $xpdo->setPackage('pfp'); $xpdo->setDebug(true); // untaint the user's data foreach($fields as $fldkey) { $fields[$fldkey] = $modx->db->escape($modx->stripTags($fields[$fldkey])); } // create and populate object $landlord = $xpdo->newObject('Landlord'); $landlord->fromArray($fields, '', true); // set binary mailing list field if ($fields['on_mailing_list'] == 'yes') $landlord->set('on_mailing_list', 1); else $landlord->set('on_mailing_list', 0); $landlord->set('web_user_id', $key); // $key has been set previously $landlord->save(); ... and finish off... ?>
CREATE TABLE `pfp_landlord` ( `id` int(10) unsigned NOT NULL auto_increment, `title` varchar(20) default NULL, `first_name` varchar(200) NOT NULL, `last_name` varchar(200) NOT NULL, `email` varchar(200) default NULL, `addr1` varchar(255) NOT NULL, `addr2` varchar(255) default NULL, `addr3` varchar(255) default NULL, `city` varchar(255) NOT NULL, `county` varchar(255) NOT NULL, `country` varchar(255) NOT NULL, `post_code` varchar(12) NOT NULL, `home_phone` varchar(30) default NULL, `work_phone` varchar(30) default NULL, `mobile` varchar(30) default NULL, `fax` varchar(30) default NULL, `date_created` timestamp NOT NULL default CURRENT_TIMESTAMP, `web_user_id` int(10) unsigned NOT NULL, `on_mailing_list` binary(1) default 'F', PRIMARY KEY (`id`), UNIQUE KEY `web_user_id` (`web_user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Contains details on landlords.' AUTO_INCREMENT=2 ;
$xpdo= new xPDO('mysql:host=localhost;dbname=pfp', "username", "password", "pfp_");