Assistance

I have written my code like this, it inserts it into the database but it doesn’t redirect back to the website I have said, If you can help…cool
[php]

<?php session_start(); include "../inc/database.php"; ?> <?php $firstName = mysqli_real_escape_string($con, $_POST['firstname']); //prevent SQL injection $lastName = mysqli_real_escape_string($con, $_POST['lastname']); $username = mysqli_real_escape_string($con, $_POST['username']); $password = mysqli_real_escape_string($con, $_POST['password']); if (strlen($password) < 8) //check if the password is a minimum of 8 characters long { $_SESSION['regoerror1'] = 'Password must be 8 characters or more.'; //if password is less than 8 characters initialise a session called 'regoerror1' to have a value of the error msgheader("location:registration.php"); //redirect to registration.php ("location:registration.php"); exit(); } $password = hash('sha256', $password); //encrypt the password $sql="SELECT * FROM login WHERE username='$username'"; //check if username is taken $result = mysqli_query($con, $sql) or die(mysqli_error($con)); //run the query $numrow=mysqli_num_rows($result); // count how many rows are returned if($numrow > 0) //if count greater than 0 { $_SESSION['regoerror2'] = 'Username taken. Please retry.'; //if an password ("location:login.php"); //redirect to registration.php exit(); } elseif ($firstName == "" || $lastName == "" || $username == "" || $password == "") //check if all fields have data { $_SESSION['regoerror3'] = 'All fields are required.'; //if an error occurs ("location:login.php"); //redirect to registration.php exit(); } else { $sql="INSERT INTO login (username, password, firstName, lastName) VALUES('$username', '$password','$firstName', '$lastName')"; $result = mysqli_query($con, $sql) or die(mysqli_error($con)); //run the query $_SESSION['regosuccess']='You created a new account.Please login'; ("location:login.php"); mysqli_close($con); } ?>

[/php]

Also now it won’t insert into the database

just change this
php; //redirect to registration.php[/php]

to
[php]header (“Location: login.php”); //redirect to registration.php[/php]

for redirection

Sponsor our Newsletter | Privacy Policy | Terms of Service