So, I'm trying to make an account creation page, but I'm having a simple error but since I'm very very new to PHP I don't understand what I've got wrong. I want it to do the command
echo "Success!";
after it has imported the data into the database. Here is the code:
if (isset($_POST['createaccount'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
DB::query('INSERT INTO users VALUES (\'\', :username, :password, :email)', array('username'=>$username, 'password'=>$password, 'email'=>$email));
echo "Success!";
I know the database import code is probably wrong but that isn't what I'm worrying about right now, thank you. I'm using PHP 5.
Well, the echo is being called after the query method is called. I guess your problem is that you are not validating if the insertion was succesfull before echoing it. If that's the case, you should store the result in a variable and analyze it, and only if everything went fine, you echo "Success!". Edit: Is this method yours? If it returns the result, you can make:
$result = DB::query('INSERT INTO users VALUES (\'\', :username, :password, :email)', array('username'=>$username, 'password'=>$password, 'email'=>$email));
And then you can see how to proceed.