错误提示为
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource newsupdate.php on line 28传递ID值代码:
<a href="newsupdate.php?id=<?php echo $row->id;?>"><img src="images/edit.gif"
newsupdate.php
include_once'connect.php';
$id = $_GET[id];
$sql = mysql_query("select * from news where id = $id");
$row = mysql_fetch_object($sql);
?>
<table width="766" border="0">
<tr>
<td width="760" height="31">当前位置----><span class="STYLE1">修改新闻</span></td>
</tr>
<tr>
<td height="32">修改信息如下:</td>
</tr>
</table>
<form name="form1" method="post" action="nchecku.php">
<table width="723" height="478" border="1" bordercolor="#339999">
<tr>
<td width="130" height="42"><div align="center" class="STYLE2">新闻标题:</div></td>
<td width="577"><label>
<input name="biaoti" type="text" value="<?php echo $row->biaoti;?>" size="80">
</label>
<input type="hidden" name="id" value="<?php echo $row->id;?>/></td>
</tr>
<tr>
<td height="51" colspan="2" /></td>
</tr>
<tr>
<td height="340"><div align="center" class="STYLE2"><strong>内容:</strong></div></td>
<td valign="middle"><label>
<textarea name="neirong" cols="80" rows="25" ><?php echo $row->neirong;?></textarea>
</label></td>
</tr>
<tr>
<td height="28"> </td>
<td><label>
<input type="submit" name="xiugai" value="修改" onClick="return checke(form1)" />
</label>
<label>
<input type="reset" name="Submit2" value="取消" />
</label></td>
</tr>
</table>
</form>
nchecku.php
<?php
include_once 'connect.php';$id = $_POST[id];
$biaoti = $_POST[biaoti];
$neirong = $_POST[neirong];
date_default_timezone_set('PRC');
$ctime = date("Y-m-d H:i:s");
$sql = mysql_query("update news set biaoti='$biaoti',neirong='$neirong',ctime='$ctime' where id = $id");
if($sql){
echo"<script>alert('信息更新成功!');window.location.href ='newschaxun.php';</script>";
}else{
echo"<script>alert('信息更新失败,请重新操作!');window.location.href ='newsupdate.php';</script>";
}
mysql_free_result($sql);
?>
调试完成后即结贴
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource newsupdate.php on line 28传递ID值代码:
<a href="newsupdate.php?id=<?php echo $row->id;?>"><img src="images/edit.gif"
newsupdate.php
include_once'connect.php';
$id = $_GET[id];
$sql = mysql_query("select * from news where id = $id");
$row = mysql_fetch_object($sql);
?>
<table width="766" border="0">
<tr>
<td width="760" height="31">当前位置----><span class="STYLE1">修改新闻</span></td>
</tr>
<tr>
<td height="32">修改信息如下:</td>
</tr>
</table>
<form name="form1" method="post" action="nchecku.php">
<table width="723" height="478" border="1" bordercolor="#339999">
<tr>
<td width="130" height="42"><div align="center" class="STYLE2">新闻标题:</div></td>
<td width="577"><label>
<input name="biaoti" type="text" value="<?php echo $row->biaoti;?>" size="80">
</label>
<input type="hidden" name="id" value="<?php echo $row->id;?>/></td>
</tr>
<tr>
<td height="51" colspan="2" /></td>
</tr>
<tr>
<td height="340"><div align="center" class="STYLE2"><strong>内容:</strong></div></td>
<td valign="middle"><label>
<textarea name="neirong" cols="80" rows="25" ><?php echo $row->neirong;?></textarea>
</label></td>
</tr>
<tr>
<td height="28"> </td>
<td><label>
<input type="submit" name="xiugai" value="修改" onClick="return checke(form1)" />
</label>
<label>
<input type="reset" name="Submit2" value="取消" />
</label></td>
</tr>
</table>
</form>
nchecku.php
<?php
include_once 'connect.php';$id = $_POST[id];
$biaoti = $_POST[biaoti];
$neirong = $_POST[neirong];
date_default_timezone_set('PRC');
$ctime = date("Y-m-d H:i:s");
$sql = mysql_query("update news set biaoti='$biaoti',neirong='$neirong',ctime='$ctime' where id = $id");
if($sql){
echo"<script>alert('信息更新成功!');window.location.href ='newschaxun.php';</script>";
}else{
echo"<script>alert('信息更新失败,请重新操作!');window.location.href ='newsupdate.php';</script>";
}
mysql_free_result($sql);
?>
调试完成后即结贴
id int
biaoti varchar
neirong mediumtext
zuozhe varchar
ctime datetime
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource newsupdate.php on line 28
这个错???
上面的错可是说的newsupdate.php 的28行有错误。
==============
出了刚开始的错误 不过出了提示框了“信息更新失败,请重新操作!”
==============
按照你的说法,貌似两个页面都执行了的??根本是两个不同的页面了,没搞明白你怎么弄的??
connect.php 如下:<?php
$link = mysql_connect("localhost","root","456789")or die ("不能连接到数据库!".mysql.error());
$db = mysql_select_db("work",$link);
mysql_query("set names 'gbk'");?>
数据库是jbk,数据表news是jbk ,但是里面有一个字段是gb2312.