$result = $conn->query没有执行!
<?phprequire_once('db_fns.php');functionregister($username,$email,$passwd){$conn=db_c...
<?php
require_once('db_fns.php');
function register($username, $email, $passwd) {
$conn = db_connect();
$result = $conn->query("select * from user where username='".$username."'");
if (!$result) {
throw new Exception('Could not execute query');
}
if ($result->num_rows>0) {
throw new Exception('That username is taken - go back and choose another one.');
}
// if ok, put in db
$result = $conn->query("insert into user values
('".$username."', sha1('".$passwd."'), '".$email."')");
if (!$result) {
throw new Exception('Could not register you in database - please try again later.');
}
return true;
}
?>
显示Could not execute query,大家看看那里出错了?
'db_fns.php'段代码如下
<?php
function db_connect() {
$result = new mysqli('localhost', ‘root’, '', 'bookmarks');
if (!$result) {
throw new Exception('Could not connect to database server');
} else {
return $result;
}
}
?> 展开
require_once('db_fns.php');
function register($username, $email, $passwd) {
$conn = db_connect();
$result = $conn->query("select * from user where username='".$username."'");
if (!$result) {
throw new Exception('Could not execute query');
}
if ($result->num_rows>0) {
throw new Exception('That username is taken - go back and choose another one.');
}
// if ok, put in db
$result = $conn->query("insert into user values
('".$username."', sha1('".$passwd."'), '".$email."')");
if (!$result) {
throw new Exception('Could not register you in database - please try again later.');
}
return true;
}
?>
显示Could not execute query,大家看看那里出错了?
'db_fns.php'段代码如下
<?php
function db_connect() {
$result = new mysqli('localhost', ‘root’, '', 'bookmarks');
if (!$result) {
throw new Exception('Could not connect to database server');
} else {
return $result;
}
}
?> 展开
Storm代理
2023-08-29 广告
2023-08-29 广告
"StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,I...
点击进入详情页
本回答由Storm代理提供
展开全部
$result = $conn->query("insert into user values
是不是没有反括号的缘故?
是不是没有反括号的缘故?
追问
不是。。。
在第一个if都没有执行下去。。。
if (!$result) {
throw new Exception('Could not execute query');
追答
既然显示了'Could not execute query',而且你这个if应该没有嵌套吧。那说明第二个if也是执行了的,只是($result->num_rows>0)这个表达式为0不为1所以后面的就没有显示出来。看看用这个思路检查下行不行。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询