超链接里传值,
get到之后不知道怎么就没了,
代码,
<?php
include("conn.php");
include("header.php"); if($_GET["id"])
{
global $id ;
$id =$_GET["id"];

$query = mysql_query("SELECT * FROM `message` WHERE `id` = $id ");

$array = mysql_fetch_array($query);

}

if($_POST['submit'])
{  $sql = "UPDATE `message` SET `user` = $_POST[user], `title` = $_POST[title],`content` = $_POST[content] `lastdate` = now() WHERE `id` = $id"; //这里$id 没有值
 
 mysql_query($sql);
 
 echo "<script language=\"javascript\">alert('修改完成');history.go(-1)</script>";
}



?>
<script type="text/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;
}
if(myform.content.value=="")
{
alert("内容不能为空");
myform.content.focus();
return false;
}

}
</script><form action="mod.php"  method="post" name="myform" onsubmit="return CheckPost();"> 用户:<input type = "text" size = "10" name = "user" value= <?php echo $array[1] ?>  /><br> 标题:<input type = "text" size = "51" name = "title"  value=<?php echo $array[2]?> /><br>

内容:<textarea name = "content" rows="10" cols="100"> <?php echo $array[3]?> </textarea><br>

<input type = "submit"  name = "submit" value="确定修改"/><br>

</form>

解决方案 »

  1.   

    是 submit 内执行sql语句时,再用 $id 不知道怎么就为空了
      

  2.   

    post的时候没有id <form action="mod.php" 怎么get
      

  3.   

    3#正解如果你非要GET获取,设置表单的action 值 mod.php?id=……
    不过这样一来,你的代码写法会导致GET  POST都会执行一次"SELECT * FROM `message` WHERE `id` = $id "
      

  4.   

    <form action="mod.php?id = <?php echo $id ?>"  method="post" name="myform" onsubmit="return CheckPost();">
    这样吗?在 if($_POST['submit'])
        {         $sql = "UPDATE `message` SET `user` = $_POST[user], `title` = $_POST[title],`content` = $_POST[content] `lastdate` = now() WHERE `id` = $id";          
             mysql_query($sql);
             
             echo "<script language=\"javascript\">alert('修改完成');history.go(-1)</script>";
        }还是不行 
      

  5.   

    mod.php?id=<?php echo $array[1];?>然后建议你把if($_GET)和if($_POST)位置换一下post放上面更改之后再读取才能看到最新的
      

  6.   

    刚才写错了是mod.php?id=<?php echo $array[0];?>
      

  7.   

    或者用<input type="hidden" 把id传过去