There has got to be a better way of doing this. First of all pay no attention to the lack of validation and error checking. I just want the core of the script to work first. Also, Block 1 and Block 2 execute, Block 3 does not. Whats the best way to check for errors on MySQLi preperation AND executions?
Ultimately what we're doing below is
1) creating the account
2) Adding a notification to the account
3) Sending a welcome message to the user via the in-site mailbox.
//REGISTER PROCESSING
if(isset($_POST['email'], $_POST["password"], $_POST['username'], $_POST['register'])){
$passwordHash = hash("sha1", $_POST["password"]);
$time = date('H:i');
$date = date("d/m/Y");
$title = "Welcome to Study Bubble!";
$content = "This is our demo training platform. It has limited functionality and is less than 30% through its development period.";
$show = "1";
$from = "Study Bubble";
$message = "We thought we should send you a test message. We can use these to engage with users and users can use the system to contact eachother.";
//BLOCK 1
$stmt = $mysqli->prepare("INSERT INTO users (authuser,authpass,authemail) VALUES (?, ?, ?)");
$stmt->bind_param('sss', $_POST['username'], $passwordHash, $_POST['email']);
$result = $stmt->execute();
if ($stmt->execute()) {
//BLOCK 2
$stmt = $mysqli->prepare("INSERT INTO notifications (user,date,time,title,content) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param('sssss', $_POST['username'], $date, $time, $title, $content);
$result = $stmt->execute();
if ($stmt->execute()) {
//BLOCK3
$stmt = $mysqli->prepare("INSERT INTO messages (to,from,date,time,message,show) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->bind_param('ssssss', $_POST['username'], $from, $date, $time, $message, $show);
$result = $stmt->execute();
if ($stmt->execute()) {
$_SESSION['auth'] = $_POST['email'];
header('Location: account-wizard.php');
}
}
}
}
So what I'm ultimately looking to learn here is:
1) Sensible way to check for errors in MySQLi (I'm googling it atm too) for debugging
2) Why block 3 isn't executing but block 1 and 2 is (number 1 should answer this for me) :D
3) A better way than nesting these: if ($stmt->execute()) {
if one exists.
Thanks in advance people, really appriciated.