#update.php:
***********************************<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<style type="text/css">
<!--
input { font-size:9pt;}
A:link {text-decoration: underline; font-size:9pt;color:000059}
A:visited {text-decoration: underline; font-size:9pt;color:000059}
A:active {text-decoration: none; font-size:9pt}
A:hover {text-decoration:underline;color:red}
body,table {font-size: 9pt}
tr,td{font-size:9pt}
-->
</style>
<title>图书馆图书资料修改</title>
</HEAD>
<body alink="#FF0000" link="#000099" vlink="#CC6600" topmargin="8" leftmargin="0" bgColor="#FFFFFF">
<br><br><center><font color=green size=3><b>图书资料</b></font></center>
<br>
-=点击书名连接进入修改页面=-
<?
//连接到本地mysql数据库
$myconn=mysql_connect("localhost","root","afei");
//选择test为操作库
mysql_select_db("library",$myconn);
if(strlen($id)<1)
{
?><table cellspacing=0 bordercolordark=#FFFFFF width="95%" bordercolorlight=#000000 border=1 align="center" cellpadding="2">
<tr bgcolor="#6b8ba8" style="color:FFFFFF">
<td width="5%" align="center" valign="bottom" height="19">ID</td>
<td width="10%" align="center" valign="bottom">书名</td>
<td width="10%" align="center" valign="bottom">作者</td>
<td width="10%" align="center" valign="bottom">出版社</td>
<td width="5%" align="center" valign="bottom">总页数</td>
<td width="5%" align="center" valign="bottom">ISBN</td>
<td width="5%" align="center" valign="bottom">关键字</td>
<td width="45%" align="center" valign="bottom">主题</td>
</tr>
<?
$strSql="select id,book_name,author,publisher,pages,isbn,book_key,title from books";
//用mysql_query函数从reguser表里读取数据
$result=mysql_query($strSql,$myconn);
while($row=mysql_fetch_array($result))//通过循环读取数据内容
{
?>
<tr>
<td align="center" height="19"><?echo $row["id"]?></td>
<td align="center"><a href="update1.php?id=<?echo $row["id"]?>"><?echo $row["book_name"]?></a></td>
<td align="center"><?echo $row["author"]?></td>
<td align="center"><?echo $row["publisher"]?></td>
<td align="center"><?echo $row["pages"]?></td>
<td align="center"><?echo $row["isbn"]?></td>
<td align="center"><?echo $row["book_key"]?></td>
<td align="center"><?echo $row["title"]?></td>
</tr>
<?
}
?>
</table>
<?
}
else if(strlen($book_name)<1)
{
$str_sql="select book_name,author,publisher,pages,isbn,book_key,title from books where id='$id'";
$result=mysql_query($str_sql,$myconn) or die(mysql_error());
$row=mysql_fetch_array($result);
?>
<form action="<? echo $PHP_SELF; ?>" method="get" name="frmAdduser">
<table cellspacing=0 bordercolordark=#FFFFFF width=780 bordercolorlight=#000000 border=1 align="center" cellpadding="2">
<tr bgcolor="#6b8ba8" style="color:FFFFFF">
<td width=780 align="center" valign="bottom" height="19" colspan="2">图书信息修改</td>
</tr>
<tr>
<td width="30%" align="right" height="19">书名:</td>
<td width="70%"><input type="text" name="book_name" size="20" maxlength="30" value="<?echo $row["book_name"]?>"></td>
</tr>
<tr>
<td width="30%" align="right" height="19">作者:</td>
<td width="70%"><input type="text" name="author" size="10" value="<?echo $row["author"]?>"></td>
</tr>
<tr>
<td width="30%" align="right" height="19">出版社:</td>
<td width="70%"><input type="text" name="publisher" size="20" maxlength="50" value="<?echo $row["publisher"]?>"></td>
</tr>
<tr>
<td width="30%" align="right" height="19">总页数:</td>
<td width="70%"><input type="text" name="pages" size="6" value="<?echo $row["pages"]?>"></td>
</tr>
<tr>
<td width="30%" align="right" height="19">ISBN:</td>
<td width="70%"><input type="text" name="isbn" size="13" value="<?echo $row["isbn"]?>"></td>
</tr>
<tr>
<td width="30%" align="right" height="19">关键字:</td>
<td width="70%"><input type="text" name="book_key" size="12" value="<?echo $row["book_key"]?>"></td>
</tr>
<tr>
<td width="30%" align="right" height=100>主题:</td>
<td width="70%" height=100><textarea name="title" cols="45" rows="7"><?echo $row["title"]?></textarea></td>
</tr>
<tr>
<td width="100%" align="center" colspan="2"><input type="submit" value="提交修改"> <input type="reset" value="重新填写"></td>
</tr>
</table>
</form>
<?
}
//如果用户填写了资料则对数据进行更新
if(strlen($book_name)>1)
{
$str_sql="update books set book_name='$book_name',author='$author',publisher='$publisher',pages='$pages',isbn='$isbn',book_key='$book_key',title='$title' where id='$id'";
//更新该ID所对应的资料
$result=mysql_query($str_sql,$myconn) or die(mysql_error());
echo "<br><br><br><center>您已经成功修改了图书资料信息!<br><br><br><br><a href=\"manage.php\">查看图书资料</a></center>";
}
//关闭对数据库的连接
mysql_close($myconn);
?>
</BODY>
</HTML>******************************
/* 另外代码里面if(strlen($id)<1)
{ …………
else if(strlen($book_name)<1)
……………… if(strlen($book_name)>1)
这几个条件语句的关系我不是很明确,请各位前辈顺便指点一下。
麻烦各位了!
谢谢
*/
***********************************<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<style type="text/css">
<!--
input { font-size:9pt;}
A:link {text-decoration: underline; font-size:9pt;color:000059}
A:visited {text-decoration: underline; font-size:9pt;color:000059}
A:active {text-decoration: none; font-size:9pt}
A:hover {text-decoration:underline;color:red}
body,table {font-size: 9pt}
tr,td{font-size:9pt}
-->
</style>
<title>图书馆图书资料修改</title>
</HEAD>
<body alink="#FF0000" link="#000099" vlink="#CC6600" topmargin="8" leftmargin="0" bgColor="#FFFFFF">
<br><br><center><font color=green size=3><b>图书资料</b></font></center>
<br>
-=点击书名连接进入修改页面=-
<?
//连接到本地mysql数据库
$myconn=mysql_connect("localhost","root","afei");
//选择test为操作库
mysql_select_db("library",$myconn);
if(strlen($id)<1)
{
?><table cellspacing=0 bordercolordark=#FFFFFF width="95%" bordercolorlight=#000000 border=1 align="center" cellpadding="2">
<tr bgcolor="#6b8ba8" style="color:FFFFFF">
<td width="5%" align="center" valign="bottom" height="19">ID</td>
<td width="10%" align="center" valign="bottom">书名</td>
<td width="10%" align="center" valign="bottom">作者</td>
<td width="10%" align="center" valign="bottom">出版社</td>
<td width="5%" align="center" valign="bottom">总页数</td>
<td width="5%" align="center" valign="bottom">ISBN</td>
<td width="5%" align="center" valign="bottom">关键字</td>
<td width="45%" align="center" valign="bottom">主题</td>
</tr>
<?
$strSql="select id,book_name,author,publisher,pages,isbn,book_key,title from books";
//用mysql_query函数从reguser表里读取数据
$result=mysql_query($strSql,$myconn);
while($row=mysql_fetch_array($result))//通过循环读取数据内容
{
?>
<tr>
<td align="center" height="19"><?echo $row["id"]?></td>
<td align="center"><a href="update1.php?id=<?echo $row["id"]?>"><?echo $row["book_name"]?></a></td>
<td align="center"><?echo $row["author"]?></td>
<td align="center"><?echo $row["publisher"]?></td>
<td align="center"><?echo $row["pages"]?></td>
<td align="center"><?echo $row["isbn"]?></td>
<td align="center"><?echo $row["book_key"]?></td>
<td align="center"><?echo $row["title"]?></td>
</tr>
<?
}
?>
</table>
<?
}
else if(strlen($book_name)<1)
{
$str_sql="select book_name,author,publisher,pages,isbn,book_key,title from books where id='$id'";
$result=mysql_query($str_sql,$myconn) or die(mysql_error());
$row=mysql_fetch_array($result);
?>
<form action="<? echo $PHP_SELF; ?>" method="get" name="frmAdduser">
<table cellspacing=0 bordercolordark=#FFFFFF width=780 bordercolorlight=#000000 border=1 align="center" cellpadding="2">
<tr bgcolor="#6b8ba8" style="color:FFFFFF">
<td width=780 align="center" valign="bottom" height="19" colspan="2">图书信息修改</td>
</tr>
<tr>
<td width="30%" align="right" height="19">书名:</td>
<td width="70%"><input type="text" name="book_name" size="20" maxlength="30" value="<?echo $row["book_name"]?>"></td>
</tr>
<tr>
<td width="30%" align="right" height="19">作者:</td>
<td width="70%"><input type="text" name="author" size="10" value="<?echo $row["author"]?>"></td>
</tr>
<tr>
<td width="30%" align="right" height="19">出版社:</td>
<td width="70%"><input type="text" name="publisher" size="20" maxlength="50" value="<?echo $row["publisher"]?>"></td>
</tr>
<tr>
<td width="30%" align="right" height="19">总页数:</td>
<td width="70%"><input type="text" name="pages" size="6" value="<?echo $row["pages"]?>"></td>
</tr>
<tr>
<td width="30%" align="right" height="19">ISBN:</td>
<td width="70%"><input type="text" name="isbn" size="13" value="<?echo $row["isbn"]?>"></td>
</tr>
<tr>
<td width="30%" align="right" height="19">关键字:</td>
<td width="70%"><input type="text" name="book_key" size="12" value="<?echo $row["book_key"]?>"></td>
</tr>
<tr>
<td width="30%" align="right" height=100>主题:</td>
<td width="70%" height=100><textarea name="title" cols="45" rows="7"><?echo $row["title"]?></textarea></td>
</tr>
<tr>
<td width="100%" align="center" colspan="2"><input type="submit" value="提交修改"> <input type="reset" value="重新填写"></td>
</tr>
</table>
</form>
<?
}
//如果用户填写了资料则对数据进行更新
if(strlen($book_name)>1)
{
$str_sql="update books set book_name='$book_name',author='$author',publisher='$publisher',pages='$pages',isbn='$isbn',book_key='$book_key',title='$title' where id='$id'";
//更新该ID所对应的资料
$result=mysql_query($str_sql,$myconn) or die(mysql_error());
echo "<br><br><br><center>您已经成功修改了图书资料信息!<br><br><br><br><a href=\"manage.php\">查看图书资料</a></center>";
}
//关闭对数据库的连接
mysql_close($myconn);
?>
</BODY>
</HTML>******************************
/* 另外代码里面if(strlen($id)<1)
{ …………
else if(strlen($book_name)<1)
……………… if(strlen($book_name)>1)
这几个条件语句的关系我不是很明确,请各位前辈顺便指点一下。
麻烦各位了!
谢谢
*/
解决方案 »
- 关于js验证表单的问题
- php4的数组里有自创类的元素,如何对其进行更改?谢谢
- PHP网页设计--做个网站真难啊。(不能说难,准确说繁)
- 有谁做过邮政国际小包183网站及国际EMS的跟踪信息抓取
- 请问.asx,.pls,.m3u个支持什么格式?上网查了一些,还是不明白
- PHP5 的 preg_replace 比旧版本慢了好多啊
- 用5.0beta3解析如下xml文档中文显示乱码,用4.3.4解析正确。莫非是5.0德bug?
- incluce,include_once,require三个函数到底分别在那些情况下使用,有何异同?
- require() 和 require_once()
- distinct 与order by 的问题及php和json的问题
- 谁有phplib模板的分页源码呀???急,还望大家不吝赐教!!!
- 我用PHP的图形函数生成图片时,为什么中文显示为乱码?
先进行从数据库中读取数据,对数据的显示,显示如下:
id,书名,。。
第二步,在书名下加链接,链接到修改页面并附上参数bookname=<?=$bookname?>或者id,最好用id可以做到唯一性,
第三根据参数从数据库中选出该条记录,并进行更新,更新时一定要先选出记录,如果有就更新,没有就退出(通过if判断来实现)
关键是要能取得值。此$id的值是不是对应books数据表里边的id字段啊?
if(strlen($id)<1)//假如$id的长度<1(从你表中可以知道id的值1110000 长度全部都是7啊)
今天没时间了,明天再看看
感觉分不是重要的,100分对我来说弄明白一个别人看来简单白痴的问题物超所值 ^^ 昨天晚上给你的留言看到了? 有时间帮忙找找问题吧 呵。to:52juanjuan(Fibona)
小弟是刚接触php不久的菜鸟 这段代码是从另一个例子代码中抠出来的
那个例子运行正确 这个却不知道怎么的 提交后一点都没变 也就是update那句根本没起作用 所以感到奇怪 实在不行 我就按大哥的思路重写一下 不过估计偶这几两水平越写越乱to:xylegend(晓逸)
$id是对应books里的id字段 这里我简化了一下 直接全部图书数据输出 然后点书名连接的时候提交变量 应该能取得 现在这段代码的主要问题出在能读出图书数据 但是修改更新不了 你运行一下一看就知道了 至于if(strlen($id)<1)这句我也看着糊涂 但是例子里面运行无误 大哥有时间帮忙调一下 谢谢!//up
//up++