Reputation: 109
My view :
<div class="container">
<form class="form-signin" method="post" action="">
<h2 class="form-signin-heading">Admin Login</h2>
<input type="text" id="inputUsername" name ="inputUsername"
class="form-control" placeholder="Admin" required autofocus />
<label for="inputPassword" class="sr-only"> Password</label>
<input type="password" id="inputPassword" name="inputPassword"
class="form-control" placeholder="Password" required />
<br/>
<button class="btn btn-lg btn-primary btn-block" name="login"
type="submit">Login</button>
</form>
</div>
My controller :
if (isset($_POST['login'])) {
$username = $_POST['inputUsername'];
$password = $_POST['inputPassword'];
echo "<script>window.location.href = 'collections.php';</script>";
}
When I clicked the button, it doesnt redirect me to collections.php , what I missed here ?
Upvotes: 0
Views: 45
Reputation: 1580
this is what you were trying outputting JS in PHP for redirection be careful with url if you use relative
$redirectURL = "../controller/collection.php";
print("<script>");
print("var t = setTimeout(\"window.location='".$redirectURL."';\", 3000);");
print("</script>");
Upvotes: 0
Reputation: 110
use php header to redirect the page ,it's easy and better compaire to what you did here. header('Location: http://www.example.com/');
Upvotes: 2
Reputation: 5264
you redirect from php
<?php
if (isset($_POST['login'])) {
$username = $_POST['inputUsername'];
$password = $_POST['inputPassword'];
header('Location: collections.php'); //<------- php redirect to other page
}
?>
Upvotes: 0