odb69 wrote:
Two things people. Firstly: feed back form, I need the php page to send me
the reply via email whilst masking the email address and for the feedback
form to return the user to to the previous page? Secondly: how could one
create a php script so that it links a flash files' submit to php which in
turn passes the data to MySQL database?
Wrote this while trying out PEAR classes:
<?php
/**
* Short script for dumping stuff out of a database
*/
require_once 'HTML/Page.php';
require_once 'HTML/QuickForm.php';
require_once 'HTML/Table.php';
require_once 'DB.php';
$p = new HTML_Page();
$f = new HTML_QuickForm('dumper');
$f->addElement('header',NULL,'Submit your query');
$f->addElement('text','query_string','SQL Query (SELECT only)',
array('size' => 80));
$f->addElement('submit',NULL,'Query');
$f->addElement('reset',NULL,'Reset query');
$p->addBodyContent($f);
if ($_POST['query_string']) {
$dsn = array('phptype' => 'mysql',
'hostspec' => 'your.host.here',
'username' => 'usr_name_here',
'password' => 'usr_passwd',
'database' => 'your_db_name');
$db =& DB::connect($dsn);
if (DB::isError($db)) { die ($db->getMessage()); }
else {
if (!preg_match("/^(UPDATE|INSERT)/i",$_POST['query_string'])) {
$query = stripslashes($_POST['query_string']);
$sth =& $db->query($query);
if (DB::isError($sth)) {
$p->addBodyContent("<p>ERROR<br>Invalid SQL query!</p>");
$p->addBodyContent("<p>" . $sth->getMessage() . "</p>");
}
else {
$t_attributes = array('rules' => 'all',
'frame' => 'border');
$t = new HTML_Table($t_attributes);
$db_header = $db->tableInfo($sth);
$headers = array();
foreach ($db_header as $c => $c_name) {
$headers = array_merge($headers,array($c_name['name']));
}
$header_attr = array('bgcolor' => 'steelblue');
$t->addRow($headers,$header_attr,'TH');
$align_attr = array ('valign' => 'top');
for ($row=0; $row < $sth->numRows(); $row++) {
$t->addRow($sth->fetchRow(), $align_attr);
}
$light = array('bgcolor' => '#CCCCCC');
$dark = array('bgcolor' => '#AAAAAA');
$t->altRowAttributes(1,$light,$dark,TRUE);
$p->addBodyContent($t);
}
}
else {
$p->addBodyContent("<p>Sorry, only SELECT queries allowed!</p>");
}
}
}
$p->display();
?>