I hope you can help. I'm a new to PHP and it is driving me crazy!
I have a html document with separate login and registration forms. Each one of these has it's own php script to either register or to login. When testing the input error messages for either the login or registration forms it seems to run both scripts and I get the error messages for both.
I have spent most of today trying to find a solution to this but to no avail. Is there a way that I can define a name to each script so I can add an action to each form tags referring to the particular php script?
Or This there a way of using a php if else statement based on which html button is pressed?
Thank you in advance
Hopeless coder
Or This there a way of using a php if else statement based on which html button is pressed?
Yes, assuming you have
<input type='submit' name='subbtn' value='Register'>
...
<input type='submit' name='subbtn' value='Log In'>
Then in php:
if ($_REQUEST['subbtn'] == 'Register') {
// they pressed register
} else {
// they pressed log in (or some other submit button)
}
You could attach a hidden element to your post method
<input type="hidden" name="type" value="login">
or
<input type="hidden" name="type" value="register">
The above should be in respective forms.
On the PHP page
<?
if($_POST['type'] == "login") {
// continue login operation
} else {
// do registration
}
?>
Sure there's a way to separate them into two files and then call for action separately.
<form action="registration.php">
...
</form>
<form action="login.php">
...
</form>
or there's another way to do it in one document
<form action="" method="POST">
...
<input type="submit" name="btn_register">
</form>
<form action="" method="POST">
...
<input type="submit" name="btn_login">
</form>
<?php
if(isset($_POST['btn_register'])) {
//Do the stuff with registration
}
if(isset($_POST['btn_login'])) {
//Do the stuff with login
}
?>