gpt4 book ai didi

php - 未使用准备好的语句存储的数据

转载 作者:可可西里 更新时间:2023-11-01 09:03:48 25 4
gpt4 key购买 nike

我只是在学习使用准备好的语句并卡在这里。正常方法没有问题。没有显示任何错误,但数据未存储在数据库中,尽管它显示“已输入数据”。

$db = new mysqli("localhost", "root","","learndb");

if ($db->connect_error) {
die("Connection failed this is the error: " . $db->connect_error);
}

$stmt = $db->prepare("INSERT INTO studentrecords (Name, email, Phone, school,dob,father,feereceived,due,image) VALUES (?,?,?,?,?,?,?,?,?)");
$stmt->bind_param("ssisssiib",$first,$email,$phone,$school,$dob,$father,$feereceived,$due,$image);
$stmt->execute();

if($stmt)
{
echo"data entered";
}

更新

数据已存储,但不是所需的类型。我应该在用户输入中指定所有类型吗? html 格式的模式也不起作用。

最佳答案

我建议您将整个 bind_param 包装起来并使用 if 条件执行,因为即使有一个小问题,语句也将无法准备。在这种情况下,我猜测可能是每个变量/字段的类型在某些时候是错误的——可能是 image/b 部分。

您可以使用 gettype 回显每个类型,这可能有助于追踪它:

echo gettype($first), gettype($email), gettype($phone),
gettype($school), gettype($dob), gettype($father),
gettype($feereceived), gettype($due), gettype($image);


$db = new mysqli("localhost", "root","","learndb");

if ($db->connect_error) {
die("Connection failed this is the error: " . $db->connect_error);
}

$stmt = $db->prepare("INSERT INTO studentrecords (`Name`, `email`, `Phone`, `school`,`dob`,`father`,`feereceived`,`due`,`image`) VALUES (?,?,?,?,?,?,?,?,?)");

if($stmt) {
$stmt->bind_param("ssisssiib",$first,$email,$phone,$school,$dob,$father,$feereceived,$due,$image);
$stmt->execute();
} else {
echo 'Failed to prepare the sql statement';
}

关于php - 未使用准备好的语句存储的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35171530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com