<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>books_update</title>
</head><body>
<h2>update books</h2>
<br/><br/>
<?php
//connect mysql
include_once "../conn.php";
$id=$_GET['update'];
$result=mysql_query("select * from books where id='$id'");
$arr=mysql_fetch_array($result);
if ($arr){?><form action="" method="post">
<table width="800" border="1" cellspacing="0" cellpadding="0" align="center" >
  <tr>
    <td width="48"  align="center" >id</td>
    <td width="161" align="center">one_head</td>
<td width="374" align="center"><input type="text" name="one_head" value="<?php echo $arr['one_head'];?>" size="30"/></td><td width="207"><?php if ($_POST['one_head']==""){ echo "<font color='#ff0000'> * not null</font>";}else{ echo "<font color='#0000ff'> true</font>";}?></td>
  </tr>
  <tr>
    <td rowspan="9" width="48"><?php echo $arr['id'] ?></td>
    <td width="161" align="center">one_body</td>
<td width="374" align="center"><input type="text" name="one_body" value="<?php echo $arr['one_body'];?>" size="30"/></td><td><?php if ($_POST['one_body']==""){ echo "<font color='#ff0000'> * not null</font>";}else{ echo "<font color='#0000ff'> true</font>";}?></td>
  </tr>
  <tr>
    <td width="161" align="center">two_head</td>
<td width="374" align="center"><input type="text" name="two_head" value="<?php echo $arr['two_head'];?>" size="30"/></td><td><?php if ($_POST['two_head']==""){ echo "<font color='#ff0000'> * not null</font>";}else{ echo "<font color='#0000ff'> true</font>";}?></td>
  </tr>
  <tr>
    <td width="161" align="center">two_body</td>
<td width="374" align="center"><input type="text" name="two_body" value="<?php echo $arr['two_body'];?>" size="30"/></td><td><?php if ($_POST['two_body']==""){ echo "<font color='#ff0000'> * not null</font>";}else{ echo "<font color='#0000ff'> true</font>";}?></td>
  </tr>
  <tr>
    <td width="161" align="center">three_head</td>
<td width="374" align="center"><input type="text" name="three_head" value="<?php echo $arr['three_head'];?>" size="30"/></td><td><?php if ($_POST['three_head']==""){ echo "<font color='#ff0000'> * not null</font>";}else{ echo "<font color='#0000ff'> true</font>";}?></td>
  </tr>
  <tr>
    <td width="161" align="center">three_body</td>
<td width="374" align="center"><input type="text" name="three_body" value="<?php echo $arr['three_body'];?>" size="30"/></td><td><?php if ($_POST['three_body']==""){ echo "<font color='#ff0000'> * not null</font>";}else{ echo "<font color='#0000ff'> true</font>";}?></td>
  </tr>
  <tr>
    <td width="161" align="center">four_head</td>
<td width="374" align="center"><input type="text" name="four_head" value="<?php echo $arr['four_head'];?>" size="30"/></td><td><?php if ($_POST['four_head']==""){ echo "<font color='#ff0000'> * not null</font>";}else{ echo "<font color='#0000ff'> true</font>";}?></td>
  </tr>
  <tr>
    <td width="161" align="center">four_body</td>
<td width="374" align="center"><input type="text" name="four_body" value="<?php echo $arr['four_body'];?>" size="30"/></td><td><?php if ($_POST['four_body']==""){ echo "<font color='#ff0000'> * not null</font>";}else{ echo "<font color='#0000ff'> true</font>";}?></td>
  </tr>
  <tr>
    <td width="161" align="center">video_head</td>
<td width="374" align="center"><input type="text" name="video_head" value="<?php echo $arr['video_head'];?>" size="30"/></td><td><?php if ($_POST['video_head']==""){ echo "<font color='#ff0000'> * not null</font>";}else{ echo "<font color='#0000ff'> true</font>";}?></td>
  </tr>
  <tr>
    <td width="161" align="center">video_body</td>
<td width="374" align="center"><input type="text" name="video_body" value="<?php echo $arr['video_body'];?>" size="30"/></td><td><?php if ($_POST['video_body']==""){ echo "<font color='#ff0000'> * not null</font>";}else{ echo "<font color='#0000ff'> true</font>";}?></td>
  </tr>
  <tr>
<td align="center" colspan="3"><input type="submit" name="update" value="update" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" name="reset" value="reset" /></td>
  </tr>
</table>
</form>
<?php
if($_POST['update']){
if (!$_POST['one_head'] && !$_POST['two_head'] && !$_POST['three_head'] && !$_POST['four_head'] && !$_POST['video_head']){
echo "<br/>";
echo "head is not null";
}elseif(!$_POST['one_body'] && !$_POST['two_body'] && !$_POST['three_body'] && !$_POST['four_body'] && !$_POST['video_body']){
     echo "<br/>";
echo "body is not null";
}else{
$result_one=mysql_query("update books set `one_head`='$_POST[one_head]',`two_head`='$_POST[two_head]',`three_head`='$_POST[three_head]',`four_head`='$_POST[four_head]',`video_head`='$_POST[video_head]',`one_body`='$_POST[one_body]',`two_body`='$_POST[two_body]',`three_body`='$_POST[three_body]',`four_body`='$_POST[four_body]',`video_body`='$_POST[video_body]' where id='$id'")or die("not successful");
echo "<br/>";
echo "<p><font color='#0000FF'>update is successful,please select the table</font></p>";
}
}
}
?>
</body></html>

解决方案 »

  1.   

    我没运行出来  一看是数据库没修改上所以还是看一下  这个语法有没有问题
    这个代码 如下
    <?php
    if($_POST['update']){
        if (!$_POST['one_head'] && !$_POST['two_head'] && !$_POST['three_head'] && !$_POST['four_head'] && !$_POST['video_head']){
            echo "<br/>";
            echo "head is not null";
        }elseif(!$_POST['one_body'] && !$_POST['two_body'] && !$_POST['three_body'] && !$_POST['four_body'] && !$_POST['video_body']){
            echo "<br/>";
            echo "body is not null";
        }else{
            $result_one=mysql_query("update books set `one_head`='$_POST[one_head]',`two_head`='$_POST[two_head]',`three_head`='$_POST[three_head]',`four_head`='$_POST[four_head]',`video_head`='$_POST[video_head]',`one_body`='$_POST[one_body]',`two_body`='$_POST[two_body]',`three_body`='$_POST[three_body]',`four_body`='$_POST[four_body]',`video_body`='$_POST[video_body]' where id='$id'")or die("not successful");
            echo "<br/>";
            echo "<p><font color='#0000FF'>update is successful,please select the table</font></p>";
        }
    }
    }
    ?>
      

  2.   

    if(isset($_POST['update'])){  //会好一点。 下面你主要是想判断什么?
      

  3.   

    帮你改了改 呵呵<?php$permit = array("A1" => 2, "A2" => 2);
    $_SESSION["A"][0] = $permit['A1'];
    $_SESSION["A"][1] = $permit['A2'];function checkPermit($e, $k) {
        if ($_SESSION["A"][$e - 1] >= $k)
            return true;
        else
            return false;
    }
    $a=$_SESSION["A"][0];
    $b=$_SESSION["A"][1];
    echo checkPermit($a, $b);
    ?>
      

  4.   

    session尽量少用吧 对服务器运行有影响。 
      

  5.   

    session是 服务器端与用户保持会话数据的方式。 他会记录在服务器的内存地址之中。如果大量的SESSION 会导致 服务器 运行性能减慢的
      

  6.   

    ...
    我以为有其他新鲜的...基本上这种可以无视.不会有人放1-200个session的.对计算机那点内存占用可以不用考虑。
      

  7.   

    例子  mysql_fetch_array 使用 MYSQL_NUM<?php
        mysql_connect("localhost", "mysql_user", "mysql_password") or
            die("Could not connect: " . mysql_error());
        mysql_select_db("mydb");    $result = mysql_query("SELECT id, name FROM mytable");    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
            printf ("ID: %s  Name: %s", $row[0], $row[1]);
        }    mysql_free_result($result);
    ?>