<?php
include("conn.php");
if(isset($_POST["submit"])){
if(mysql_query("update tb_leaveword set title='".$_POST["title"]."',content='".$_POST["content"]."' where id='".$_POST["id"]."'",$conn)){
$url=urlencode("查看留言");
echo "<script>alert('留言更改成功!');window.location.href='index.php?id=$url';</script>"; }else{
echo "<script>alert('留言更改失败!');window.location.href='index.php?id=$url';</script>";
}
exit;
}
$id=$_GET["ed"];
$sql=mysql_query("select * from tb_leaveword where id='".$id."'",$conn);
$info=mysql_fetch_array($sql);
?><table>
<tr>
<td></td>
</tr>
</table>
<table width="550" height="200" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF"bgcolor="#FCD424"> <script language="javascript">
function chkinput(form){
if(form.title.value==""){ alert("留言主题不能为空!");
form.title.focus();
return(false); } if(form.content.value==""){ alert("留言内容不能为空!");
form.content.focus();
return(false); }
return(true); } </script> <form name="form1" method="post" action="editleaveword.php" onSubmit="return chkinput(this)"> <tr>
<td height="25" colspan="2" background="images/dh_back_1.gif" bgcolor="#FFFFFF"> <img src="images/biao.gif"> 编辑留言</td>
</tr>
<tr>
<td width="76" height="25" bgcolor="#FFFFFF"><div align="center">留言主题:</div></td>
<td width="371" bgcolor="#FFFFFF"> <input name="title" type="text" class="inputcss" size="45" value="<?php echo $info['title'];?>"></td>
</tr>
<tr>
<td height="200" bgcolor="#FFFFFF"><div align="center">留言内容:</div></td>
<td height="200" bgcolor="#FFFFFF"> <textarea name="content" cols="52" rows="12" class="inputcss"><?php echo $info['content'];?></textarea></td>
</tr>
<tr>
<td height="25" colspan="2" bgcolor="#FFFFFF"><div align="center"><input type="hidden" name="id" value="<?php echo $_GET['ed'];?>"><input type="submit" value="编辑" class="buttoncss" name="submit"> <input type="reset" value="取消" class="buttoncss"></div></td>
</tr>
</form></table>
这段代码无法实现显示数据库内容?是不是没有获取到ID呢?
关于编辑,我也不知道从何入手,从何写起,希望大家多多指教,谢谢!
include("conn.php");
if(isset($_POST["submit"])){
if(mysql_query("update tb_leaveword set title='".$_POST["title"]."',content='".$_POST["content"]."' where id='".$_POST["id"]."'",$conn)){
$url=urlencode("查看留言");
echo "<script>alert('留言更改成功!');window.location.href='index.php?id=$url';</script>"; }else{
echo "<script>alert('留言更改失败!');window.location.href='index.php?id=$url';</script>";
}
exit;
}
$id=$_GET["ed"];
$sql=mysql_query("select * from tb_leaveword where id='".$id."'",$conn);
$info=mysql_fetch_array($sql);
?><table>
<tr>
<td></td>
</tr>
</table>
<table width="550" height="200" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF"bgcolor="#FCD424"> <script language="javascript">
function chkinput(form){
if(form.title.value==""){ alert("留言主题不能为空!");
form.title.focus();
return(false); } if(form.content.value==""){ alert("留言内容不能为空!");
form.content.focus();
return(false); }
return(true); } </script> <form name="form1" method="post" action="editleaveword.php" onSubmit="return chkinput(this)"> <tr>
<td height="25" colspan="2" background="images/dh_back_1.gif" bgcolor="#FFFFFF"> <img src="images/biao.gif"> 编辑留言</td>
</tr>
<tr>
<td width="76" height="25" bgcolor="#FFFFFF"><div align="center">留言主题:</div></td>
<td width="371" bgcolor="#FFFFFF"> <input name="title" type="text" class="inputcss" size="45" value="<?php echo $info['title'];?>"></td>
</tr>
<tr>
<td height="200" bgcolor="#FFFFFF"><div align="center">留言内容:</div></td>
<td height="200" bgcolor="#FFFFFF"> <textarea name="content" cols="52" rows="12" class="inputcss"><?php echo $info['content'];?></textarea></td>
</tr>
<tr>
<td height="25" colspan="2" bgcolor="#FFFFFF"><div align="center"><input type="hidden" name="id" value="<?php echo $_GET['ed'];?>"><input type="submit" value="编辑" class="buttoncss" name="submit"> <input type="reset" value="取消" class="buttoncss"></div></td>
</tr>
</form></table>
这段代码无法实现显示数据库内容?是不是没有获取到ID呢?
关于编辑,我也不知道从何入手,从何写起,希望大家多多指教,谢谢!
}else{
echo "<script>alert('留言更改失败!');window.location.href='index.php?id=$url';</script>";
}
//exit();//注释掉exit();
}
//====================
$id=$_GET["ed"];
$sql=mysql_query("select * from tb_leaveword where id='".$id."'",$conn);$info=mysql_fetch_array($sql);
修改为 (可以不修改,但建议你修改)
$info=mysql_fetch_assoc($sql);
//===================
1.检测 $id 是否正确提交echo $id;2.检测返回数组是否正常
print_R($info);如果2正常返回结果 那么将结果发出来.
if(isset($_SESSION['unc'])){
$sql=mysql_query("select id from tb_user where `Usernc`='".$_SESSION['unc']."'") or die (mysql_error());
$info=mysql_fetch_array($sql);
$useid=$info['id'];
if( $useid){
$sql="select * from tb_leaveword";
$query1=mysql_query($sql);
$row=mysql_fetch_array($query1);
//echo $row[id];
$_SESSION[uid]= $row[id];//这里用来保存用户登录和留言的ID
} if(isset($_POST["submit"])){ //判断用户是否提交按钮,如果提交,可以更改代码
if(mysql_query("update tb_leaveword set title='".$_POST["title"]."',content='".$_POST["content"]."' where id='".$_POST["id"]."'",$conn)){
$url=urlencode("查看留言");
echo "<script>alert('留言更改成功!');</script>"; }else{
echo "<script>alert('留言更改失败!');</script>";
}
//exit;
}
$id=$_SESSION[uid];
echo $sql="select * from tb_leaveword where id='".$id."'";
$query=mysql_query($sql);
$info=mysql_fetch_array($query);
print_r($info);//这里是用户单击"编辑"按钮,则查询该用户留言内容,将最终的留言显示表单中
}
<table>
<tr>
<td></td>
</tr>
</table>
<table width="550" height="200" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF"bgcolor="#FCD424"> <script language="javascript">
function chkinput(form){
if(form.title.value==""){ alert("留言主题不能为空!");
form.title.focus();
return(false); } if(form.content.value==""){ alert("留言内容不能为空!");
form.content.focus();
return(false); }
return(true); } </script> <form name="form1" method="post" action="editleaveword.php" onSubmit="return chkinput(this)"> <tr>
<td height="25" colspan="2" background="images/dh_back_1.gif" bgcolor="#FFFFFF"> <img src="images/biao.gif"> 编辑留言</td>
</tr>
<tr>
<td width="76" height="25" bgcolor="#FFFFFF"><div align="center">留言主题:</div></td>
<td width="371" bgcolor="#FFFFFF"> <input name="title" type="text" class="inputcss" size="45" value="<?php echo $info['title'];?>"></td>
</tr>
<tr>
<td height="200" bgcolor="#FFFFFF"><div align="center">留言内容:</div></td>
<td height="200" bgcolor="#FFFFFF"> <textarea name="content" cols="52" rows="12" class="inputcss"><?php echo $info['content'];?></textarea></td>
</tr>
<tr>
<td height="25" colspan="2" bgcolor="#FFFFFF"><div align="center"><input type="hidden" name="id" value="<?php echo $row[id];?>"><input type="submit" value="编辑" class="buttoncss" name="submit"> <input type="reset" value="取消" class="buttoncss"></div></td>
</tr>
</form></table>