中华网通行证
用户名 密码
  科技动态 硬件广场 下载基地 网络教室 网络冲浪 科学博览 移动时代 手机上网 桌面壁纸 科技商情  

生成支持“编辑纪录”功能的代码

编辑记录

您看完了前面的教程,有些比较麻烦,那您是否认为编辑一个存在的记录很难呢?

哈哈! 实事上正好相反,编辑记录很容易.

最难的只不过是创建一个编辑表单,如果您没有特别的需要,您可以用我们前面的表单,这样就省却了这桩难事.

再不您也可以用FontPage、Dreamweaver等程序生成HTML代码(这就较为容易)

转入正题! 我们用两步来完成这个功能:

第一步、生成编辑表单。

这个您可以看看下面程序里Html部分,还有为了减少朋友们读程序时的困扰,我尽量不改变前面的程序代码,我在程序中重写这段Html代码。如果您想让程序更紧密一点,您可以稍加修改。

第二步、生成一个MySQL语句来执行命令(update)。

修改我们的script_select2.php

在前面删除代码后写入一句(下面蓝颜色代码)

while ($record=mysql_fetch_object($result)) {
print("<tr><td><font color=$key_scrit_color>".$record->key_script.
"</font><td><font color=$date_created_color>".$record->date_created.
"</font><td><font color=$date_updated_color>".$record->date_updated.
"</font><td><font color=$script_name_color>".$record->script_name.
"</font><td><font color=$script_size_color>".$record->script_size.
"</font><td><font color=$script_explain_color>".$record->script_explain.
"</font><td><font color=$author_name_color>".$record->author_name.
"</font><td><font color=$author_email_color>".$record->author_email.
"</font><td><font color=$author_homepage_color>".$record->author_homepage.
"</font>" );
print"<td><a href=\"script_delete.php?action=delete_record&key_record= $record->key_script\">删除</a>";
print"<td><a href=\"script_update.php?action=html_update&key_record= $record->key_script\">编辑</a>";
}

同时生成一个文件script_update.php(这个基本上是script_insert_action.php的翻版,蓝色为改动部分)

<?php

require('connect.inc');
if($arr_request['action']=='update')
{
$current_date=date('Y-m-d H:i:s'); /*把当前时间按YYYY-MM-DD HH:MM:SS方式排列*/
$script_name=$arr_request['script_name'];
$script_size=$arr_request['script_size'];
$script_explain=$arr_request['script_explain'];
$author_name=$arr_request['author_name'];
$author_email=$arr_request['author_email'];
$author_homepage=$arr_request['author_homepage'];
/*这样一替换,处理时就好多了*/
$str_sql="update $tablename
set
date_updated='$current_date',
script_name='$script_name',
script_size='$script_size',
script_explain='$script_explain',
author_name='$author_name',
author_email='$author_email',
author_homepage='$author_homepage'
where key_script='$key_record'";
您可以看看updqte语句的用法

$result=mysql_db_query($dbname,$str_sql,$link_id);
/* 下面给用户简单的信息反馈 */
if (!$result){html_error_exit('MySQL编辑命令失败!');}
else {html_header('成功');
echo"<center>";
echo('MySQL编辑命令成功');
echo("<br><a href=\"script_select2.php?action=show_data\">显示记录</a>");
html_footer();
}
}
//结束update命令

else //输出HTML 代码
{ //读出需要编辑的记录的信息
$str_sql="select * from $tablename where key_script=$key_record";
$result=mysql_db_query($dbname,$str_sql,$link_id);
if (!$result){html_error_exit('MySQL 选择命令执行错误');}
$record=mysql_fetch_object($result);
html_header('请编辑信息');
?>
<table width="68%" border="0" align="center">
<tr bgcolor="#CCCCCC"> <td height="214">
<form method="post" action="<?php echo $PATH_INFO ?>">
<table width="80%" border="1" align="center">
<tr>
<td width="32%">程序名:</td>
<td width="68%"> <input type="text" name="script_name" value="<?php echo"$record->script_name" ?>" size="20" maxlength="20"> </td>
</tr>
<tr>
<td width="32%" height="31">文件大小:</td>
<td width="68%" height="31"><input type="text" name="script_size" value="<?php echo"$record->script_size" ?>" size="10" maxlength="10"> </td>
</tr>
<tr>
<td width="32%">程序描述:</td>
<td width="68%"> <textarea name="script_explain"cols="40"><?php echo"$record->script_explain" ?></textarea> </td>
</tr>
<tr>
<td width="32%">作者名:</td>
<td width="68%"> <input type="text" name="author_name" value="<?php echo"$record->author_name" ?>" size="20" maxlength="20"> </td>
</tr>
<tr>
<td width="32%">作者邮件地址:</td>
<td width="68%"> <input type="text" name="author_email" value="<?php echo"$record->author_email" ?>" size="20" maxlength="20"> </td>
</tr>
<tr>
<td width="32%">作者的主页:</td> <td width="68%">
<input type="text" name="author_homepage" value="<?php echo"$record->author_homepage" ?>" size="30" maxlength="30"> </td>
</tr>
</table>
<div align="center">
<input type="hidden" name="key_record" value="<?php echo"$key_record" ?>">
<input type="hidden" name="action" value="update">
<input type="submit" name="Submit" value="更新纪录">
<input type="reset" name="Reset" value="恢复">
</div>
</form>
</td>
</tr>
</table>
<?php
html_footer();
}
?>

难吗?应该不难吧!

  《PHP之星》 Siron/文

  
相关报道




本站检索



中华网推荐

·国家级治脑病新药思维源
·中藏药治疗脑病新突破
·治类风湿,强直性脊柱炎
·养肾·痛风·长寿
·肝病泌尿脑萎缩新药介绍
·强直性脊柱炎康复乐园
·让中医辩证不孕不育
·国医治股骨头坏死一绝
·乙肝为何久治不愈?
·二千元垄断批发做老板
·中医中药专治前列腺
·治牛皮癣白癜风已成现实
·专治痛风病的白衣天使
·不孕不育的杏林奇葩
·专卖店零售管理系统





   

网络教室编辑信箱