Good morning,
I am trying to use MySqli Multi-query to put variables that are posted by the login script in two different database tables; the common details need to be posted in the wp_users table, and the uncommon details need to be posted in the wp_users_info-table I've made myself.
I am trying to use the following code to do that:
<?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
}
}
?>
And if I run this code, I get the following errors: Does anybody know how to use the code to make it work?
Sorry for my bad English, I'm from Holland.
Jeffrey
You can use two separate prepared queries like below:
// 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();