user863739
user863739

Reputation: 299

PHP MYSQL header() location

I have a class that inserts users into a database, although I'm having a little trouble initialising header() re-direct. Here is my code

    public function Register() {

    $username = $_POST['username'];
    $password = $_POST['password'];

    $query = mysql_query("INSERT INTO users (username, password, admin) VALUES ('$username', '$password', '0')");
    header('Location: /view_registered.php?register=success');



}

Is there a way I can put the header within a variable then once the method's complete adding users to the db then pass the header variable back to my index.php page?

kind regards

Upvotes: 3

Views: 6377

Answers (4)

Caimen
Caimen

Reputation: 2619

Try adding a .

header('Location: ./view_registered.php?register=success');

If in a folder below

header('Location: ./../view_registered.php?register=success');

If in a folder above

header('Location: ./FOLDER_NAME_HERE/view_registered.php?register=success');

If in a different place altogether

header('Location: http://www.google.com');

Upvotes: 3

Timur
Timur

Reputation: 6718

What trouble? May be you need to use output buffering ( http://www.php.net/manual/en/ref.outcontrol.php )?

Upvotes: 0

xkeshav
xkeshav

Reputation: 54050

use mysql_affected_rows()

$query = '';
if(mysql_affected_rows) {
header();
exit();
}

Upvotes: 0

David Nguyen
David Nguyen

Reputation: 8508

if($query)
header('Location: /view_registered.php?register=success');

Upvotes: 0

Related Questions