php - MySQLi更新和死亡();和退出();不工作

标签 php mysql mysqli exit die

我正在尝试用 MySQLi 替换我的 MySQL,我得到了结果 - 没关系,但是当涉及到更新 MySQL 时,我的代码失败了(我只更新了 MySQL 部分)

inc_mysql_connect.php

$db = mysqli_connect($host, $user, $pass, $dbase) or die (); 

inc_global_functions.php

if($_POST['costAlertTrue'] != "") {

// CHECKS AND IF ERROR - REDIRECT BACK
if(..) {$_SESSION['status'] ="E1"; header("Location: ./?page=cAlert"); exit();}
if(..) ...

// SQL
$sql = "UPDATE ".$dbprfx."_users SET costAlertVar = ? WHERE connection = ?";
$eintrag = $db->prepare($sql);
if ($eintrag->error()) { print($eintrag->error()); }
$eintrag->bind_param('ss',$costAlertVar,$userConnection);
$eintrag->execute();
$eintrag->close();

// REDIRECT 
$_SESSION['status'] ="on"; header("Location: ./?page=cAlert");

} // End

有人能找出这段代码中的错误吗?

注意事项

if($_POST['costAlertTrue'] != "") {
die('XX'); exit('XX');
}

好像die();导出();或任何其他错误在 if 子句中不起作用

最佳答案

$eintrag->error(); {die('Not Working');} 每次都会死掉,即使一切都很好,因为 PHP 会看到语句 $eintrag->error() 和代码块 {die('不工作');}.

你应该这样使用:

if (!$eintrag->error()) { die('Not Working'); }

关于php - MySQLi更新和死亡();和退出();不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20401810/

相关文章:

php - 如何使用 Codeigniter mymodel 类在多个 where 条件下进行更新?

PHP登录重定向流程

php - 如何在 PHP PDO 中简单地将一个值绑定(bind)到所有参数?

php - html表单将数据输入到mysql数据库

php - 不同开发环境下的 Laravel

php - Left 排除 JOIN 的问题

mysql - 如何选择同一列中的条目并将其差异添加到附加结果列中?

php - 我应该为验证目的创建一个 temporary_users 表吗?

php - 使用 PHP 在 MySQL 数据库中存储多个图像

php - 如何使用 PHP 插入特殊字符 int mysqldb