php修改数据库记录,求大神 php 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $wno和$wname值随便取,即使与数据库中的serial_no和emp_name不匹配,竟然也提示修改成功,回到数据库命令行下查看,明显修改不成功的,为什么这里会提示修改成功(即$query_update返回TRUE) 你执行之后,把SQL语句打印出来,复制到数据库执行,就知道什么问题 你应该仔细看看mysql_query() 返回值那一部分。 这个也需要大神...只是没有修改的记录而已,语句本身没问题自然不会返回false。如果你一定要判断这种状态,建议获取修改的影响行数。 PHP修改数据库信息示例//显示数据库信息修改操作<?php if($page){ $page_size=6; //每页显示2条记录 $query="select count(*) as total from tb_url where tb_url_id"; //从数据库中读取数据 $result=mysql_query($query); $message_count=mysql_result($result,0,"total"); //获取总的记录数 $page_count=ceil($message_count/$page_size); //获取总的页数 $offset=($page-1)*$page_size; $query=mysql_query("select * from tb_url where tb_url_id order by tb_url_id desc limit $offset, $page_size");while($myrow=mysql_fetch_array($query)){?> <tr> <td height="25" align="center"><span class="STYLE1"><?php echo $myrow[tb_url_name];?></a></span></td> <td align="center"><span class="STYLE1"><?php echo $myrow[tb_url_dz];?></span></td> <td align="center"><span class="STYLE1"><?php echo $myrow[uptime];?></span></td> <td align="center"><a href="liulan_up_ok.php?tb_url_id=<?php echo $myrow[tb_url_id];?>" class="STYLE1">修改信息</a></td> <td align="center"><a href="delete_liulan_type.php?delete_id=<?php echo $myrow[tb_url_id];?>" class="STYLE1">删除会员</a></td> </tr><?php }}?>//codego.net/tags/4/1///点击修改信息跳转页面处理修改信息功能<?php $sql=mysql_query("select * from tb_url where tb_url_id='$_GET[tb_url_id]'"); while($myrow=mysql_fetch_array($sql)){ ?><form action="up_liulan_up.php" method="post" enctype="multipart/form-data" name="form1" id="form1" onSubmit="return check_input(form1)"><div id="up"><div id="up1">友情连接修改</div><div id="yonghum">连接地址:</div><div id="tupmc">连接名称:</div><div id="tupmc2"> <label> <input type="text" id="tb_url_name" name="tb_url_name" size="30" value="<?php echo $myrow[tb_url_name] ?>"></label></div><div id="tupmc1"> <input name="tb_url_dz" id="tb_url_dz" type="text" size="30" value="<?php echo $myrow[tb_url_dz]; ?>"></div><div id="anniu"> <input type="submit" name="submit" value="修改" /> <a href="index.php">返回</a><label> </label></a></div> </div></form><?php}?> mysql_query對於无效SQL的时候是返回FALSE,如果SQL查询结果为空(语句是有效的),仍然是会返回有效的ID。所以判斷是否有更新不能這樣判斷。應該使用mysql_affected_rows()判斷。mysql_affected_rows() 函数返回前一次 MySQL 操作所影响的记录行数。參考:http://www.w3school.com.cn/php/func_mysql_affected_rows.asp$query_update = @mysql_query("update employees set userlevel = $wlevel where serial_no = '$wno' and emp_name = '$wname'") or die("SQL语句执行失败!");$rc = mysql_affected_rows(); if($rc) { echo "修改成功!<br><br>"; } else echo "Sorry,修改失败!"; 请教pdo时不时就不能正常跑的问题,头晕啊!!! PHP 编码 phpinfo 中--without-gd如何解决 精确控制php传值 php日期函数提问 如何取得页面的网址和传递参数啊? 终于升了一级---小乐子与大家同享,顺便散分,周五下班前结贴 syre(神仙)进来领分,感谢回答PHP+Socket的应用,问题已经OK. 好怪,为什么会自动加2? 本地可以用 “./” 与 "../" ,服务器上不能用 咋么在PHP中定义变量? php语法和优先级的我呢天
如果你一定要判断这种状态,建议获取修改的影响行数。
//显示数据库信息修改操作
<?php
if($page){
$page_size=6; //每页显示2条记录
$query="select count(*) as total from tb_url where tb_url_id"; //从数据库中读取数据
$result=mysql_query($query);
$message_count=mysql_result($result,0,"total"); //获取总的记录数
$page_count=ceil($message_count/$page_size); //获取总的页数
$offset=($page-1)*$page_size;
$query=mysql_query("select * from tb_url where tb_url_id order by tb_url_id desc limit $offset, $page_size");
while($myrow=mysql_fetch_array($query)){
?>
<tr>
<td height="25" align="center"><span class="STYLE1"><?php echo $myrow[tb_url_name];?></a></span></td>
<td align="center"><span class="STYLE1"><?php echo $myrow[tb_url_dz];?></span></td>
<td align="center"><span class="STYLE1"><?php echo $myrow[uptime];?></span></td>
<td align="center"><a href="liulan_up_ok.php?tb_url_id=<?php echo $myrow[tb_url_id];?>" class="STYLE1">修改信息</a></td>
<td align="center"><a href="delete_liulan_type.php?delete_id=<?php echo $myrow[tb_url_id];?>" class="STYLE1">删除会员</a></td>
</tr>
<?php }}?>//codego.net/tags/4/1/
//点击修改信息跳转页面处理修改信息功能
<?php
$sql=mysql_query("select * from tb_url where tb_url_id='$_GET[tb_url_id]'");
while($myrow=mysql_fetch_array($sql)){
?><form action="up_liulan_up.php" method="post" enctype="multipart/form-data" name="form1" id="form1" onSubmit="return check_input(form1)">
<div id="up">
<div id="up1">友情连接修改</div>
<div id="yonghum">连接地址:</div>
<div id="tupmc">连接名称:</div><div id="tupmc2">
<label>
<input type="text" id="tb_url_name" name="tb_url_name" size="30" value="<?php echo $myrow[tb_url_name] ?>">
</label>
</div>
<div id="tupmc1">
<input name="tb_url_dz" id="tb_url_dz" type="text" size="30" value="<?php echo $myrow[tb_url_dz]; ?>"></div>
<div id="anniu"> <input type="submit" name="submit" value="修改" />
<a href="index.php">返回</a>
<label>
</label>
</a></div>
</div>
</form>
<?php
}
?>
所以判斷是否有更新不能這樣判斷。
應該使用mysql_affected_rows()判斷。mysql_affected_rows() 函数返回前一次 MySQL 操作所影响的记录行数。參考:http://www.w3school.com.cn/php/func_mysql_affected_rows.asp
$query_update = @mysql_query("update employees set userlevel = $wlevel where serial_no = '$wno' and emp_name = '$wname'")
or die("SQL语句执行失败!");$rc = mysql_affected_rows(); if($rc)
{
echo "修改成功!<br><br>";
}
else
echo "Sorry,修改失败!";