Populate a table within my mysql DB using data submitted on template page of the new 'Example' module's interactive initialization functions (within pninit.php). I'm using PN .761
The function i am concerned with is:
example_init_step2() to be exact.
Code
function example_init_step2()
{
// This is part two of the interactive installation procedure. We will ask the user for some basic data now. After collecting the data, we store them session vars.
// Check permissions
if (!pnSecAuthAction(0, '::', '::', ACCESS_ADMIN)) {
return pnVarPrepHTMLDisplay(_MODULENOAUTH);
}
// submit is set if the users sends his data. We can use the same function here for presenting our form and handle the users input.
$submit = pnVarCleanFromInput('submit');
if(!$submit) {
// submit is not set, show the form now
$pnr =& new pnRender('example');
$pnr->caching = false;
return $pnr->fetch('example_init_step2.htm');
} else {
// submit is set, read the data and store them.
if (!pnSecConfirmAuthKey()) {
pnSessionSetVar('errormsg', pnVarPrepHTMLDisplay(_BADAUTHKEY));
return pnRedirect(pnModURL('Modules', 'admin', 'view'));
}
// submit is set, assign the post data into string variables
list($firstname, $lastname, $company, $email, $activate ) = pnVarCleanFromInput('firstname', 'lastname', 'company', 'email', 'activate');
// We do not store the values directly in the mod vars but put them in to a session var first. This will be read in the _init function. So we keep backwards compatible with .750 or earlier
pnSessionSetVar('example_firstname', $firstname);
pnSessionSetVar('example_lastname', $lastname);
pnSessionSetVar('example_company', $company);
pnSessionSetVar('example_email', $email);
$activate = (!empty($activate)) ? true : false;
$dbconn =& pnDBGetConn(true);
$pntable =& pnDBGetTables();
$example_admin_data_table = &$pntable['example_admin_data'];
$example_admin_data_column = &$pntable['example_admin_data_column'];
$dict = &NewDataDictionary($dbconn);
$taboptarray =& pnDBGetTableOptions();
$sql = "INSERT INTO $example_admin_data_table VALUES ( '$firstname', '$lastname' , '$company' ,'$email' )";
// I use the two lines below for testing the sql output.
// echo $sql;
// die();
$result = $dbconn->Execute($sql);
}
// we are ready now and redirect to the function that is responsible for installing a module
return pnRedirect(pnModURL('example', 'init', 'step3', array('activate' => $activate)));
}
{
// This is part two of the interactive installation procedure. We will ask the user for some basic data now. After collecting the data, we store them session vars.
// Check permissions
if (!pnSecAuthAction(0, '::', '::', ACCESS_ADMIN)) {
return pnVarPrepHTMLDisplay(_MODULENOAUTH);
}
// submit is set if the users sends his data. We can use the same function here for presenting our form and handle the users input.
$submit = pnVarCleanFromInput('submit');
if(!$submit) {
// submit is not set, show the form now
$pnr =& new pnRender('example');
$pnr->caching = false;
return $pnr->fetch('example_init_step2.htm');
} else {
// submit is set, read the data and store them.
if (!pnSecConfirmAuthKey()) {
pnSessionSetVar('errormsg', pnVarPrepHTMLDisplay(_BADAUTHKEY));
return pnRedirect(pnModURL('Modules', 'admin', 'view'));
}
// submit is set, assign the post data into string variables
list($firstname, $lastname, $company, $email, $activate ) = pnVarCleanFromInput('firstname', 'lastname', 'company', 'email', 'activate');
// We do not store the values directly in the mod vars but put them in to a session var first. This will be read in the _init function. So we keep backwards compatible with .750 or earlier
pnSessionSetVar('example_firstname', $firstname);
pnSessionSetVar('example_lastname', $lastname);
pnSessionSetVar('example_company', $company);
pnSessionSetVar('example_email', $email);
$activate = (!empty($activate)) ? true : false;
$dbconn =& pnDBGetConn(true);
$pntable =& pnDBGetTables();
$example_admin_data_table = &$pntable['example_admin_data'];
$example_admin_data_column = &$pntable['example_admin_data_column'];
$dict = &NewDataDictionary($dbconn);
$taboptarray =& pnDBGetTableOptions();
$sql = "INSERT INTO $example_admin_data_table VALUES ( '$firstname', '$lastname' , '$company' ,'$email' )";
// I use the two lines below for testing the sql output.
// echo $sql;
// die();
$result = $dbconn->Execute($sql);
}
// we are ready now and redirect to the function that is responsible for installing a module
return pnRedirect(pnModURL('example', 'init', 'step3', array('activate' => $activate)));
}
The SQL that's being output to the screen is good to go, I can initialize the module.. and all the tables and indexes are being created okay... but the data just isn't populating the tables at this point. Does anyone know how i can write the info that's in those variables (the ones i grabbed from the form's submit action) and write them to my database??
I want to take info submitted at the initialization stage and add it to the database tables using the adodb dictionary syntax, the tables have already previously created by the function pninvoice_init().
Any help would be much appreciated.
