As an example of how to use prepared statements, you could use the following (not tested btw)
In the source code, you sent headers after the output of the html code - this will cause an error if you do not use output buffering, so I moved all the relevant PHP code before any html content was created, and if there were any errors, print them later.
I also noticed that the parameters for the mysqli connection were not specified - if they were defined as constants, then this would be good, otherwise it could also cause errors.
Keep mysqli or pdo - as you can better protect your sites from malicious users when you accept prepared statements, as I tried to show here.
<?php require_once("functions.php"); require_once("db-const.php"); session_start(); if (logged_in() == true) { redirect_to("profile.php"); } $errors=array(); if( $_SERVER['REQUEST_METHOD'] == 'POST' ) { if( isset( $_POST['username'], $_POST['password'], $_POST['first_name'], $_POST['last_name'], $_POST['email'] ) ) { $username = !empty( $_POST['username'] ) ? $_POST['username'] : false; $mainpass = !empty( $_POST['password'] ) ? $_POST['password'] : false; $password = !empty( $mainpass ) ? hash('sha256', $mainpass) : false; $first_name = !empty( $_POST['first_name'] ) ? $_POST['first_name'] : false; $last_name = !empty( $_POST['last_name'] ) ? $_POST['last_name'] : false; $email = !empty( $_POST['email'] ) ? $_POST['email'] : false; if( $username && $password ){ $mysqli = new mysqli( DB_HOST, DB_USER, DB_PASS, DB_NAME ); if( $mysqli->connect_errno ) { $errors[]=$mysqli->connect_error; } else { $sql='select username from users where username=?'; $stmt=$mysqli->prepare($sql); $stmt->bind_param('s',$username); $stmt->execute(); $stmt->bind_result( $found ); $stmt->fetch(); if( !$found ){ $sql='insert into `users` (`username`,`password`,`first_name`,`last_name`,`email`) values (?,?,?,?,?);'; $stmt=$mysqli->prepare( $sql ); $stmt->bind_param('sssss',$username,$password,$first_name,$last_name,$email); $stmt->execute(); header("Location: checklogin.php?msg=Registered Successfully!"); } else { $errors[]='Sorry, that username is already in use.'; } } } } else { $errors[]='Please fill in all details'; } } ?> <html> <head> <title>Prospekt Member Area</title> </head> <body> <h1> Register Here </h1> <h2>© Kirk Niverba</h2> <hr /> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Username: <input type="text" name="username" /><br /> Password: <input type="password" name="password" /><br /> First name: <input type="text" name="first_name" /><br /> Last name: <input type="text" name="last_name" /><br /> Email: <input type="type" name="email" /><br /> <input type="submit" name="submit" value="Register" /> <a href="login.php">Already have an account?</a> </form> <?php if( !empty( $errors ) ){ echo implode( '<br />', $errors ); } ?> <hr /> </body> </html>