I'm aware this question has been asked millions of times but hopefully this is slightly different as i can't seem to find an answer. I'm trying to redirect back to the index page (where login takes place) after a successful sign up process. Ideally
header("Location: index.php");
would be used. However, i can't use that as part of my PHP validation uses echo's. The code i have below works perfectly. Using
<script>
window.location.href = "index.php";
</script>
This is the end part of my validation code:
//loads of other form validation using echo's
...
{
$resultusername = queryMysql("SELECT * FROM members WHERE username='$username'");
if ($resultusername->num_rows)
{
echo <<<_END
<div id=usernameinuse>
<p>This username is already in use!</p>
</div>
_END;
}
else
{
$qresult = queryMysql("INSERT INTO members (firstname,
surname, gender, dob, email, username, password)
VALUES('$firstname', '$surname', '$gender', '$dob', '$email', '$username', '$password')");
echo <<<_END
<script>
window.location.href = "index.php";
</script>
_END;
}
Like i said this works perfectly, however, I'd ideally like all jquery and javascript to be in separate files from my php and linked at the top of the file (other jquery files are already up there) and want to avoid going into javascript in the middle of a php file. So my question is, is there a way to make that script external and catch it in a jquery file like
$('input[type=submit]').click && ($qresult)(function() {
window.location.href = 'index.php';
return false;
}
This works without the && ($qresult)
bit, but then if you just click submit, non of the validation takes place and nothing is entered into the database.
I'm also aware PDO is a lot better to use and mysql functions are slightly obsolete but i'm just getting used to everything. Thanks