+ -
当前位置:首页 → 问答吧 → 这个哪里有错了 高手看一下 谢了

这个哪里有错了 高手看一下 谢了

时间:2011-09-02

来源:互联网

PHP code

<!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>




作者: yhwl2258   发布时间: 2011-09-02

报什么错?

作者: xuzuning   发布时间: 2011-09-02

没报错 应该是 没有正确连接数据库

作者: yhwl2258   发布时间: 2011-09-02

那你要我看什么?

作者: xuzuning   发布时间: 2011-09-02

不知道楼主要问什么。还是把问题说清楚一点,不然都帮助不了。

作者: wswssx   发布时间: 2011-09-02

我没运行出来 一看是数据库没修改上

所以还是看一下 这个语法有没有问题
这个代码 如下

PHP code

<?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>";
    }
}
}


?>




作者: yhwl2258   发布时间: 2011-09-02

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

作者: jordan102   发布时间: 2011-09-02

额 会了

作者: yhwl2258   发布时间: 2011-09-02

相关阅读 更多