Home > Backend Development > PHP Tutorial > PHP的mysql安插请求返回无报错,但数据库未更新

PHP的mysql安插请求返回无报错,但数据库未更新

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:59:51
Original
1113 people have browsed it

PHP的mysql插入请求返回无报错,但数据库未更新

本帖最后由 dimply 于 2014-06-13 21:46:24 编辑 有下面这段PHP代码

$query = "insert into index_base (cardid, name, sex, nationality, birth, address, issued, expiration) values ($cardid, $name, $gender, $folk, $birthday, $addr, $agency, $expire)";<br />mysql_query($query);<br />if($buy=="1"){<br />	$bid = mysql_insert_id();<br />echo($bid);<br />	$time=date("Y-m-d",time());<br />	$time.=":1";<br />	$query = "insert into index_b2a (bid, aid, `limit`, now) values ($bid, $aid, '$time', 1)";<br />echo($query);<br />	$result = mysql($query);<br />	echo("result 为".$result);<br />	if(mysql_affected_rows()==1)die("1");<br />	else die("0");<br />}
Copy after login


根据echo和die返回的值来看,请求 $query = "insert into index_b2a (bid, aid, `limit`, now) values ($bid, $aid, '$time', 1)";应该是完全没错,$result为1,且affected rows也是1。
但是在数据库里,怎么也找不到插入的这一条在哪里。

我加了一个echo($query),打印出来的请求为insert into index_b2a (bid, aid, `limit`, now) values (102631, '89', '2014-06-13:1', 1),直接输入mysql,当然也是执行正确的,并且刷新数据库后,立刻能看到插入的条目。

因为limit是关键字,我已经加了``作为引号。
为了确保不会造成错误,89外面的引号也去掉,2014-06-13:1这个值也改了,把后面冒号和数字1去掉。
然后执行:
仍然是mysql里面能生效,php里面不生效,但返回值都说是执行成功。

不知道问题出在哪里?
------解决方案--------------------
$result = mysql($query); 中的mysql() 是你自定义的函数么?还是手误?

echo mysql_error(); 看看有没有错误。
------解决方案--------------------
$result = mysql($query); 这个是什么?
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template