一个非常让人费解的问题,高手快进来看看!

true_mariner 2006-07-27 01:08:50
我有一个sql语句,
$str="update $table set xibie='$xibie' where id='$id'";
其中,$id是上一个页面附加地址传递过来的,用echo也能够输出$id,但是这句语句就是不执行,如果给 $id付值例如$id="5"; 这句语句就能准确无误的执行,请问这是怎么问题??
...全文
588 37 打赏 收藏 转发到动态 举报
写回复
用AI写文章
37 条回复
切换为时间正序
请发表友善的回复…
发表回复
shjxj 2006-08-08
  • 打赏
  • 举报
回复
$str1="update zhuanye set xibie='$xibie' where id='$id'";
yumin0903 2006-07-29
  • 打赏
  • 举报
回复
$id=$_GET['id'];
echo $id;
参数传入了没有?我怀疑你没有传入参数id.
用这种办法检测.
if($_GET['id']!=null)
{
$id=$_GET['id'];
}
else
{
echo "参数没有传入";
}
true_mariner 2006-07-29
  • 打赏
  • 举报
回复
好象是没有传入,怎么修改呀 ?
helloyou0 2006-07-28
  • 打赏
  • 举报
回复
调试sql错误,首先看mysql_error()的输出是什么

true_mariner 2006-07-28
  • 打赏
  • 举报
回复
如果将这段代码的id直接用数字来写的话,例如
$str="update $table set xibie='$xibie' where id='6'";
起他的代码不用改,就可以正确地执行,请问怎么解决??
true_mariner 2006-07-28
  • 打赏
  • 举报
回复
$str="update $table set xibie='$xibie' where id=$id";

去掉$id的小分号!

我试过了,这样也是不行.
还有id是int型的

if(strlen($xibie)!==0) //另外,这个条件是错的,只有在判断变量是否为真假采用===,!==比较符号。否则请老老实实用==,可能这才是你不运行sql查询的根源。
这个办法我也试过了,同样是不执行
liiawgmm 2006-07-28
  • 打赏
  • 举报
回复
update zhuanye set xibie='11' where id='6'
你在"6"写重新写一下,就可以了,写成以下这样
update zhuanye set xibie='11' where id='6'

看到了吗,是不是有点不同,这个我试过了,没错的
yueyang 2006-07-28
  • 打赏
  • 举报
回复
前面的人其实已经说的很充分了,根本就是书写错误造成的。
还解决不了,看来你得自己检查一下是否和你描述的一致了。
firstrose 2006-07-28
  • 打赏
  • 举报
回复
把echo $str1;放在if语句里面。这样就可以知道那句sql有没有执行!
另外,id的类型是什么?

你可以用Maguma调试一下
arfeng75 2006-07-28
  • 打赏
  • 举报
回复
$str="update $table set xibie='$xibie' where id=$id";

去掉$id的小分号!
Kvci 2006-07-28
  • 打赏
  • 举报
回复
id字段是什么类型?
lvlfforever 2006-07-28
  • 打赏
  • 举报
回复
真费劲!问题归根到底就是$id是空!
true_mariner 2006-07-28
  • 打赏
  • 举报
回复
我用intval函数将$id转换一下:
$s=intval($id);
echo $s;
$str1="update zhuanye set xibie='".$xibie."' where id='$s'";
最后执行
echo $str1;
echo $id;
echo $s;
结果输出的结果是:update zhuanye set xibie='666' where id='0'0

如果不对$id进行转换,那么输出结果是:
update zhuanye set xibie='666' where id=''
true_mariner 2006-07-28
  • 打赏
  • 举报
回复
什么都没有输出.
tony_zeng 2006-07-27
  • 打赏
  • 举报
回复
首先,这个问题不是什么高深问题,所以不要用“高手快进来”这样的字眼。

这是一个很基本的调试技能。
?
<?php
include("connect.php");
$db="bookticket";
$table="zhuanye";
$xibie=$_GET['xibie'];
$jibie=$_GET['jibie'];
$zhuanye=$_GET['zhuanye'];
$banji=$_GET['banji'];
$id=$_GET['id'];
echo $id;
if(strlen($xibie)!==0) //另外,这个条件是错的,只有在判断变量是否为真假采用===,!==比较符号。否则请老老实实用==,可能这才是你不运行sql查询的根源。
{

$str1="update zhuanye set xibie='".$xibie."' where id='".$id."'";
$res=mysql_db_query($db,$str1) or die( 'ERROR in mysql query. Error code: '. mysql_errno() . ', error msg: ' . mysql_error() ) ; ////////按照错误提示输出mysql错误
}
echo $id;
echo $str1;
?>
levopat 2006-07-27
  • 打赏
  • 举报
回复
本人托管一台p4 3.0 双CPU至强机器在专业电信机房,

带宽共享1G,

想搞个专业的PHP论坛。

现在征求志愿者加入。本人可为版主提供免费的PHP主页空间(共享1G空间)。

联系QQ:235749
zeroleonhart 2006-07-27
  • 打赏
  • 举报
回复
run it under phpmyadmin and see the error message.
true_mariner 2006-07-27
  • 打赏
  • 举报
回复
kongguyoulan163(空谷幽兰163)
我的代码贴出来了,你怎么不回复了呢
true_mariner 2006-07-27
  • 打赏
  • 举报
回复
数字是我加上去的,没有问题,我贴上来的时候打错了
zeroleonhart 2006-07-27
  • 打赏
  • 举报
回复
update zhuanye set xibie='11' where id='6'

is $id a number ???
is $xibie a number , too ???

I see the "6" here is 全角字符.....
加载更多回复(17)

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧