我写了一个脚本,它从数据库动态生成数据并输出到表中,现在我希望将相同的数据插入到数据库中。 我该如何实现这一目标?
我想要一种方式,管理员可以查询数据库以查找用户提交的任务(用户提交的任务将以表格形式显示),然后撰写报告或对其进行审核,然后提交。在提交报告的过程中,我希望将提交的报告插入到数据库的另一个表中,这样用户仍然可以查询数据库以便管理员读取提交的报告。
实际上,我还没有尝试过任何东西,因为我不知道该尝试什么,我在谷歌搜索解决方案但找不到任何解决方案。
使用添加了4/30的代码进行编辑(为了便于阅读):
<?php include('simple_html_dom.php');
if(isset($_REQUEST['submit'])) {
$html = file_get_html('cpanel.php');
foreach($html->find('a') as $td)
echo $td. '<br>';
$user = $_REQUEST['uname'];
$title = $_REQUEST['utitle'];
$desc = $_REQUEST['udesc'];
$_date = $_REQUEST['udate'];
$ucom = $_REQUEST['comment'];
echo $ucom;
$query = "INSERT INTO viewreport(Username, Title, Description, Report, Date) VALUES()";
?>
答案 0 :(得分:1)
听起来你想在第一个查询中允许管理员注释并将这些注释存储在单独的数据库表中?
您可能使用的流程概述:
例如:
<?php
// get_database_info.php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
$db_selected = mysql_select_db ( 'database_name' );
if ( first display AND $db_selected ) {
// check user for admin
if ( admin ) {
$query = 'SELECT field1, field2, ... FROM table1 WHERE ...';
} else $query = 'SELECT comments, field1, field2, ... from table1 WHERE ...';
$result = mysql_query ( $query );
// Process & build the data to show in <body>
$show = '...';
// Add a form at the bottom for admin comments
if ( admin ) {
$show .= '<form method="post" action="get_database_info.php">';
// Add input fields for user & comment
$show .= '....';
}
}
elseif ( submit comments AND $db_selected ) {
// Build and enter insert query
$insert_query = 'INSERT INTO table2 ( field1, ... ) VALUES ( 'abc', ... )';
// Get result and build <body>
$show = '...';
}
else
$show = 'There was an error connecting to the database to process your request.';
?>
<html>
<body>
<?php echo $show; ?>
</body>
</html>