rendered paste body<?php
require_once 'MDB2.php';
require_once 'DBConnect.php'; //Where I set the $mdb2 [avoids sharing password]
require_once 'DB/Table.php';
require_once 'DataSchema.php';
$tablename = "testme";
$auto_create = 'safe';
$book =& new InvoiceUsers($mdb2, $tablename, $auto_create);
//$book->fetchmode = DB_FETCHMODE_ASSOC;
if ($book->error) {
echo "Failure! Try again.";
print_r($book->error);
die;
}
if (isset($_REQUEST['op'])) {
if ($_REQUEST['op']=="Save"){
$id = $book->nextID();
$cols_vals = array(
/*
var $col = array(
'id' => array('type' => 'integer', 'require' => true, 'qf_type'=>'hidden'),
'name' => array('type' => 'varchar', 'size' => 32, 'qf_label'=> 'Name (e.g. "John Smith")', 'qf_attrs'=> array('style'=>'background:#f00;')),
'address' => array('type' => 'clob', 'qf_type'=> 'textarea'),
'phone' => array('type' => 'varchar', 'size' => 32, 'qf_type'=>'text', 'qf_label'=> 'Phone number') ,
'email' => array('type' => 'varchar', 'size' => 128, 'require' => true ,'qf_type'=>'text'),
'signdate'
*/
'id' => $id,
'name' => mysql_real_escape_string($_REQUEST['name']),
'address' => mysql_real_escape_string($_REQUEST['address']),
'phone' => mysql_real_escape_string($_REQUEST['phone']),
'email' => mysql_real_escape_string($_REQUEST['email']),
'signdate' => date('Y-m-d') // Todays Date.
);
$result = $book->insert($cols_vals);
print_r($result);
} // op = save
} else {
// display these following cols
$cols = array(
'name', 'address', 'phone', 'email'
/* // Default Date Detting
'signdate' => array(
"Y" => date("Y"),
"m" => date("m"),
"d" => date("d")
) */
);
//print_r($cols);// double checking.
//$form =& $book->getForm($cols);
$form =& $book->getForm($cols);
$form->addElement('submit', 'op', 'Save'); // add a "submit" button named "op" that says "Go!"
$form->addElement('reset', '', 'Reset'); // add a reset button
//phpinfo(32);
$form->display();
$result = $book->select('list');
echo "<pre><table>\n";
foreach ($result as $id){
print_r($id);
echo "<tr><td>".$id."</td>";
foreach ($id as $content => $val){
echo "<td>".nl2br($val)."</td>";
}
echo "</tr>\n";
}
echo "</table></pre>";
//$result = $book->selectResult('emails'); print_r($result);
}
?>