MySQLi 多查询不起作用
MySQLi Multi Query doesn't work
早上好,
我正在尝试使用 MySqli 多查询将登录脚本发布的变量放入两个不同的数据库 table;常见的要在wp_userstable里发,不常见的要发在wp_users_info-table我自己做的
我正在尝试使用以下代码来执行此操作:
<?php
if (isset($_POST['btn-signup'])) {
$uname = mysqli_real_escape_string($con, $_POST['uname']);
$achternaam = mysqli_real_escape_string($con, $_POST['achternaam']);
$upass = md5(mysqli_real_escape_string($con, $_POST['pass']));
$datum = mysqli_real_escape_string($con, $_POST['datum']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$basisschool = mysqli_real_escape_string($con, $_POST['basisschool']);
$opleidingsduur = mysqli_real_escape_string($con, $_POST['opleidingsduur']);
$bsgroep = mysqli_real_escape_string($con, $_POST['bsgroep']);
$url = '#leerling';
$fullname = $uname . ' ' . $achternaam;
if (mysqli_multi_query($con,"INSERT INTO wp_users (user_login,user_pass,user_nicename,user_email,user_url,user_registered,display_name) VALUES ('$email','$upass','$uname','$email','$url','now()','$fullname'); INSERT INTO wp_users_info (user_voornaam,user_achternaam,user_geboortedatum,user_basisschool,user_opleidingsduur,user_groep) VALUES('$uname','$achternaam','$datum','$basisschool','$opleidingsduur','$bsgroep')" )) {
?> <script>alert('Je hebt een account aangemaakt en vanaf nu kun je jezelf inloggen! ');</script><?php
echo '<script>window.location = "' . $link2 . '";</script>';
} else {
?>
<script>alert('Fout bij het registreren...');</script>
<?php
}
}
?>
如果我 运行 这段代码,我会得到以下错误:
有人知道如何使用代码使其工作吗?
抱歉我的英语不好,我来自荷兰。
杰弗里
只是不要使用多查询。这不是你想的那样。
为您的插入使用两个单独的准备查询。
您可以使用两个单独的准备好的查询,如下所示:
// prepare and bind Users Query
$queryUsers = $conn->prepare("INSERT INTO wp_users(user_login,user_pass,user_nicename,user_email,user_url,user_registered,display_name) VALUES (?, ?, ?, ?, ?, ?, ?)");
$queryUsers->bind_param("sssssss",$email,$upass,$uname,$email,$url,$now,$fullname);
// execute Users Query
$queryUsers->execute();
// prepare and bind Users Info Query
$queryUsersInfo = $conn->prepare("INSERT INTO wp_users_info (user_voornaam,user_achternaam,user_geboortedatum,user_basisschool,user_opleidingsduur,user_groep) VALUES (?, ?, ?, ?, ?, ?)");
$queryUsersInfo->bind_param("ssssss",$uname,$achternaam,$datum,$basisschool,$opleidingsduur,$bsgroep);
// execute Users Info Query
$queryUsersInfo->execute();
// Close Connections
$queryUsers->close();
$queryUsersInfo->close();
早上好,
我正在尝试使用 MySqli 多查询将登录脚本发布的变量放入两个不同的数据库 table;常见的要在wp_userstable里发,不常见的要发在wp_users_info-table我自己做的
我正在尝试使用以下代码来执行此操作:
<?php
if (isset($_POST['btn-signup'])) {
$uname = mysqli_real_escape_string($con, $_POST['uname']);
$achternaam = mysqli_real_escape_string($con, $_POST['achternaam']);
$upass = md5(mysqli_real_escape_string($con, $_POST['pass']));
$datum = mysqli_real_escape_string($con, $_POST['datum']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$basisschool = mysqli_real_escape_string($con, $_POST['basisschool']);
$opleidingsduur = mysqli_real_escape_string($con, $_POST['opleidingsduur']);
$bsgroep = mysqli_real_escape_string($con, $_POST['bsgroep']);
$url = '#leerling';
$fullname = $uname . ' ' . $achternaam;
if (mysqli_multi_query($con,"INSERT INTO wp_users (user_login,user_pass,user_nicename,user_email,user_url,user_registered,display_name) VALUES ('$email','$upass','$uname','$email','$url','now()','$fullname'); INSERT INTO wp_users_info (user_voornaam,user_achternaam,user_geboortedatum,user_basisschool,user_opleidingsduur,user_groep) VALUES('$uname','$achternaam','$datum','$basisschool','$opleidingsduur','$bsgroep')" )) {
?> <script>alert('Je hebt een account aangemaakt en vanaf nu kun je jezelf inloggen! ');</script><?php
echo '<script>window.location = "' . $link2 . '";</script>';
} else {
?>
<script>alert('Fout bij het registreren...');</script>
<?php
}
}
?>
如果我 运行 这段代码,我会得到以下错误:
抱歉我的英语不好,我来自荷兰。
杰弗里
只是不要使用多查询。这不是你想的那样。
为您的插入使用两个单独的准备查询。
您可以使用两个单独的准备好的查询,如下所示:
// prepare and bind Users Query
$queryUsers = $conn->prepare("INSERT INTO wp_users(user_login,user_pass,user_nicename,user_email,user_url,user_registered,display_name) VALUES (?, ?, ?, ?, ?, ?, ?)");
$queryUsers->bind_param("sssssss",$email,$upass,$uname,$email,$url,$now,$fullname);
// execute Users Query
$queryUsers->execute();
// prepare and bind Users Info Query
$queryUsersInfo = $conn->prepare("INSERT INTO wp_users_info (user_voornaam,user_achternaam,user_geboortedatum,user_basisschool,user_opleidingsduur,user_groep) VALUES (?, ?, ?, ?, ?, ?)");
$queryUsersInfo->bind_param("ssssss",$uname,$achternaam,$datum,$basisschool,$opleidingsduur,$bsgroep);
// execute Users Info Query
$queryUsersInfo->execute();
// Close Connections
$queryUsers->close();
$queryUsersInfo->close();