php更新记录代码 麻烦看下哪里错了
php吧
全部回复
仅看楼主
level 1
woshidlc 楼主
<?php
$link_id = mysql_connect ( "localhost", "root", "123" ) or die ( "链接失败" );
if ($link_id) {
 mysql_select_db ( "aa" );
 if ($_GET [id]) {
  $result = mysql_query ( "select * from userinfo" );
  echo "
         <table border = 1>
         <tr>
         <td>编号</td>
         <td>用户</td>
         <td>性别</td>
         <td>年龄</td>
         <td>操作</td>
         </tr>";
  while ( $row = mysql_fetch_array ( $result ) ) {
   echo "<tr>
   <td>" . $row [id] . "</td>
   <td>" . $row [username] . "</td>
   <td>" . $row [gender] . "</td>
   <td>" . $row [age] . "</td>
   <td><a href=modify.php?id=" . $row [id] . ">编辑</a></td>
   </tr>
   ";
  }
  echo "</table>";
 } else {
  if (! $_POST[ok]) {
   $sql = "select * from userinfo where id=" . $_GET [id];
   $result = mysql_query ( $sql );
   $row = mysql_fetch_array ( $result );
   ?>
<from method=post action='modify.php?id=<?
   echo $_GET [id];
   ?>'>
<?
   echo $row [id] . "<br>";
   ?>
<input type="hidden" name="id" value=<?
   echo $row [id];
   ?>>
姓名
<input type=text name="username"
 value=<?
   echo $row [username];
   ?>>
性别
<input type=text name="username" value=<?
   echo $row [gender];
   ?>>
年龄
<input type=text name="username" value=<?
   echo $row [age];
   ?>>
<input type=submit name=ok value="提交">
<?
  } else {
   $sql = "update userinfo set username='" . $row [username] . "',gender='" . 
   $row [gender] . "',age='" . $row [age] . "' where id='" . $_POST [id] . "'";
  $result = mysql_query($sql);
  if ($result)
  echo "记录已经成功修改<br><a href='modify.php'>继续修改</a>";
  else 
  echo "记录修改失败<br><a href='modify.php?=".$_POST[id]."'>返回</a>";
  }
 }
}
?> 
2009年07月16日 12点07分 1
level 7
我的乖乖,我好久没有写这种代码了.
这个还使用短标签.真是一个不太好的习惯.
没有对$_GET值处理,也不是一个好习惯.
input标签name有重复,这好像也不对.
总起来说,LZ一串代码,我是无能为力.看起来太费劲了.
2009年07月17日 15点07分 2
level 0
<td><? echo $row [id]?></td> 
   <td><? echo $row [username]?></td> 
   <td><? echo $row [gender]?></td> 
   <td><? echo $row [age]?></td> 
这是好的习惯
2009年09月25日 03点09分 3
level 1
这代码也太不简洁了吧?还用PHP输入HTML?执行效率也太低了吧
2009年11月13日 13点11分 4
1