I'm making a website, and have been trying to write javascript in a PHP file to create an alert, then depending on if the user clicks "ok" or "cancel", it takes them to different pages. I got a javascript code that should work in an HTML file, but the PHP file doesn't read it for some reason.
This is for a XAMPP server, running MySQL, PHP, HTML, CSS, javascript, and Apache. I tried pasting this into my PHP file, but it doesn't read properly.
if ($sessioncode != "Admin-placebojoe" || "Mizzy-renegade") {
loginFail();
} else {
loginSuccess();
}
function loginFail() {
var txt;
var r = confirm("Account does not exist. Either check credentials and try again, or press ok to Sign Up.");
if (r == true) {
txt = header("refresh:6; url=Signup.html");
} else {
txt = header("refresh:0; url=Login.html");
}
}
The PHP file rejects the line where it says var txt;
on line 8. The error message reads:
Parse error: syntax error, unexpected 'var' (T_VAR) in C:\xampp***** on line 13
(I left out a few lines at the beginning that's why it's line 13). This tells me that the error is the PHP file cant read the JavaScript.
How can I make the PHP file read and execute all of the JavaScript code?