Notice: Undefined index: id in E:\wamp\wamp\www\liuyanbanban\modify.php on line 问题

来源:互联网 发布:java编程技术培训 编辑:程序博客网 时间:2024/04/29 21:03

以下是我在写modify.php时遇到的问题:

问题一:代码出现Notice: Undefined index: id in E:\wamp\wamp\www\liuyanbanban\modify.php on line这样的错误提示

解决方法:在两个if语句的判断语句里添加isset(),即形式为if(isset(判断语句))

这是因为在一开始还没收到submit,所以才会有这样的提示。

问题二:再修改之后,list网页中的信息不会修改

解决方法:由此可知,可能是sql语句出现了错误

我之前所写的错误的sql语句为: $sql="update message set title=$_POST[title',content=$_POST[content] where id=$_GET[id]";

正确的为: $sql="update message set title='$_POST[title]',content='$_POST[content]' where id=$_GET[id]";

即引号非常重要



我的代码:modify.php

<meta charset='UTF-8'>
<?php
//error_reporting(0);
include("conn.php");
if(isset($_POST['submit'])){
    $sql="update message set title='$_POST[title]',content='$_POST[content]' where id=$_GET[id]";
    mysql_query($sql);
    echo "<script>alert('修改成功');location.href='list.php'</script>";
}
if(isset($_GET['id'])){
    $sql="select * from message where id=$_GET[id]";
    $query=mysql_query($sql);
    while($row=mysql_fetch_array($query))
    {
?>
<html>
<head>
<title>
新闻修改
</title>
<SCRIPT language=javascript>
function CheckPost()
{
 if(myform.user.value=="")
 {
  alert("请填写用户名");
  myform.user.focus();//光标聚焦
  return false;
 }
 if(myform.title.value.length<5)
 {
  alert("标题不能少于5个字符");
  myform.title.focus();
  return false;
 }
}
</SCRIPT>
</head>
<body>
<form action="" method="post" name="myform" onsubmit="return CheckPost()">
用户:<input type="text" name="user" value=<?php echo $row['user']?>><br>
标题:<input type="text" name="title" value=<?php echo $row['title']?>><br>
内容:<input type="text" name="content" value=<?php echo $row['content']?>><br>
<?php
}
?>
<input type="submit" name="submit" value="修改">
<?php
}
?>
</form>
</body>
</html>


0 0
原创粉丝点击