i have two submit button in form and i used Switch case method to implement the code. One for SignIn page ie it redirects to another page other for NewUser page and this one should redirect to another registration page.
but my code is not working and below is the code.
<?php
switch($_POST['submit'])
{
case 'SignIn':
header('Location : http://localhost/eproject/UserPage.php');
break;
case 'NewUser':
echo "NEw user page resgistri";
break;
default:
echo "Dont know what you are doing ! ";
break;
}
?>
<table>
<form name="form8" method="post" >
<tr><td>Cutomer Username</td><td><input type="text" name="uname"></td></tr>
<tr><td>Customer Password</td><td><input type="password" name="pwd"</td></tr>
<tr><td><input type="submit" value="SignIn" name="submit"></td><td><input type="submit" value="NewUSer" name="submit"></td></tr>
</form>
</table>
value="NewUSer"
in the HTML
NewUser
in the PHP
S
it would be better to use a hidden input field like:
<input type="hidden" name="thefieldname" value="thevalue" />
then you can use the switch statement like this:
switch($_POST['thefieldname']){
case '':
.....
break;
}
To easily find out mistakes like these (NewUSer instead of NewUser), if the code is not working, first use GET method and check if it is working. If it is not, check all GET variables in the address bar. This will help to make debugging simple.
After a
header("location: ....
one should always use a
die();
to avoid having the rest of the script processed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.