I've finally made what I think is a good, secure and fast way to execute a query, but I want to be completely sure before I implement it all over the site.
My code:
$email = $_POST['email'];
$displayName = $_POST['displayName'];
$pass = $_POST['pass1'];
if($stmt = $link -> prepare("INSERT INTO profiles (email, displayName, password) VALUES (?, ?, md5(?))")) {
/* Bind parameters
s - string, b - boolean, i - int, etc */
$stmt -> bind_param("sss", $email, $displayName, $pass);
/* Execute it */
$stmt -> execute();
echo "You are now registered.<br />";
echo "<a href=\"login.php\">Login</a>";
/* Close statement */
$stmt -> close();
}
BTW, what does stmt mean/stand for?
EDIT, NEW CODE:
/* Create a prepared statement */
$stmt = $link -> prepare("INSERT INTO profiles (email, displayName, password,
dateRegistered) VALUES (?, ?, md5(?), NOW())");
if ( false===$stmt ) {
die('prepare() failed: ' . htmlspecialchars($link->error));
}
$rc = $stmt -> bind_param("sss", $email, $displayName, $pass);
if ( false===$rc ) {
die('bind_param() failed: ' . htmlspecialchars($stmt->error));
}
/* Execute it */
$rc = $stmt->execute();
if ( false===$rc ) {
die('execute() failed: ' . htmlspecialchars($stmt->error));
}
echo "You are now registered.<br />";
echo "<a href=\"login.php\">Login</a>";
/* Close statement */
$stmt -> close();