note 41287 added to ref.mysql
| From: | scott at millerco dot net | Date: | Mon, 05 Apr 2004 16:23:04 +0000 |
| Subject: | note 41287 added to ref.mysql | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-67666@lists.php.net to get a copy of this message | ||
I wrote this script to help me quickly make rough drafts of database applications. All you have to
do is define your database then browse this page. It returns a html form that is already setup to
use Smarty forms. (http://smarty.php.net) It also uses a double underscore in the field names so
that they can be parsed into a multi dimensional variable with the format:
$formdata[table][field][value].
This array in turn can be looped to produce MySQL queries to insert your test data.
The $table variable is hard coded, but it can be set to $_GET["table"] so that you can
specify the table from the url.
Anyway the script is simple and it demonstrates several really cool aspect of the flexible
interaction of PHP with MySQL. Enjoy!
<?php
$user = "****";
$password = "****";
$database = "****";
$host = "localhost";
$link = mysql_connect($host, $user, $password);
mysql_select_db($database, $link);
$table = "table_name";
$db_result = mysql_query ("DESCRIBE " . $table, $link);
//print_r($db_info);
?>
<FORM name="new_patient_data" id="new_patient_data" method="post"
action="?app={$form_data.app}">
<TABLE border="0" width="200" cellspacing="2"
cellpadding="2" rules="cols" align="center">
<?php
while ($db_info = mysql_fetch_array($db_result, MYSQL_ASSOC)) {
if (substr_count($db_info["Type"], "text")) {
?>
<TR>
<TD nowrap>
<?php echo $db_info["Field"] ?>
</TD>
<TD nowrap>
<TEXTAREA name="<?php echo $table . "__" . $db_info["Field"]
?>">{$form_data.<?php echo $table . "__" . $db_info["Field"]
?>}</TEXTAREA>
</TD>
</TR>
<?php
} else {
eregi("\((.*)\)", $db_info["Type"], $size);
?>
<TR>
<TD nowrap>
<?php echo $db_info["Field"] ?>
</TD>
<TD nowrap>
<INPUT name="<<?php echo $table . "__" . $db_info["Field"]
?>" type="text" value="{$form_data.<?php echo $table; ?>__<?php echo
$db_info["Field"]; ?>}" size="<?php echo $size[1]; ?>"
maxlength="<?php echo $size[1]; ?>" />
</TD>
</TR>
<?php
}
}
?>
<TR>
<TD nowrap> </TD>
<TD nowrap><INPUT type="submit" name="Submit"
value="Submit" /></TD>
</TR>
</TABLE>
</FORM>
----
Manual Page -- http://www.php.net/manual/en/ref.mysql.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41287
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41287&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41287&report=yes
Search -- http://master.php.net/manage/user-notes.php