I'm just getting into mysql and i am creating a basic registration page. However, when i click submit, i want to be directed to another page, say a page where you login, as many sites have.
How do i go about allowing the submit button to link to a new page. I know it'll be something simple, but i have looked and can't seem to find much on it.
This is the current code that i've tried:
<html>
<head>
<title>MySQL Test - Registration</title>
<script LANGUAGE="JavaScript">
function testResults() {
window.document.location.href = "http://www.google.com";
}
</script>
</head>
<body>
<form action = "rego.php" method = "POST">
Username:<br/>
<input type = "text" name = "username"/><br/>
Password:<br/>
<input type = "password" name = "password"/><br/>
Confirm Password:<br/>
<input type = "password" name = "passvery"/><br/>
Email:<br/>
<input type = "text" name = "email"/><br/><br/>
Please select your gender:<br/>
<input type = "radio" name = "gender" value = "male"/>Male      
<input type = "radio" name = "gender" value = "female"/>Female<br/><br/>
<input type = "checkbox" name = "agree" value = "agree"/>I agree to the terms and conditions.<br/>
<br/>
<input type = "submit" value = "Sign Up!" onclick = "javascript:testresults()" />
</form>
</body>
</html>
Form action="rego.php" means that your form will be submitted to that file.
If you want to go somewhere else after rego.php, you should redirect from that file, for example using the location header, before any output:
// do stuff (registration)
header("Location: another-php.php");
Related
I have created a basic sign in form:
<form action = "" type = "post">
<input type = "text" name = "txt_user" placeholder = "Username" required/>
<input type = "password" name = "txt_pass" placeholder = "Password" required/>
<input type = "submit" name = "btn_submit" value = " Sign In ">
and posted this above my html:
<?php
if(isset($_POST['btn_submit'])) {
$username = $_POST['txt_user'];
echo $username;
?>
to see if the form works, it doesn't. The txt_user won't display up top the html as it should be but instead change my url from this:
localhost:8080/tryouts
to this:
http://localhost:8080/tryout/?si_username=asd&si_password=asdasd&si_submit=++Sign+In++
can you tell me what's going on? I tried this method before and it works. Maybe I misplaced something?
Update
The page containing the form is called signin.php where it's been placed inside index.php like this:
<body>
<?php include("signin.php"); ?>
</body>
purpose of this is to save time and space for the php codes so that I won't be bother changing the sign in form from page to page, instead just changed the signin page main php page. I don't think it's causing this but still...
You need to set your form method to POST; form type is invalid. Right now, it's defaulting to using GET.
<form action = "" method = "post">
<input type = "text" name = "txt_user" placeholder = "Username" required/>
<input type = "password" name = "txt_pass" placeholder = "Password" required/>
<input type = "submit" name = "btn_submit" value = " Sign In ">
I am totally new to PHP, just one of my friends asked to modify his site and I trying to do this, since he think programmers can do everything.
I needed to create text field and button, then insert something into database after button is pressed.
I done it that by creating a form like that in default.php:
<form action = 'default.php' method = 'get'>
<input type = 'text' id = 'txt_teacher_name' name = 'txt_teacher_name' />
<input type = 'submit' value = 'Set' />
</form>
And this code is loaded in page when address bar have this address: http://onigra.net/cp2/index.php?page=default
After pressing the button address changes to this: http://onigra.net/cp2/default.php?txt_teacher_name=zxc and I getting 404 error.
What I need to do to make submit this form and stay on same page?
You need change to your source like this
<form action = 'index.php' method = 'get'>
<input type = 'text' id = 'txt_teacher_name' name = 'txt_teacher_name' />
<input type = 'hidden' name = 'page' value = 'default' />
<input type = 'submit' value = 'Set' />
</form>
Your url should be http://onigra.net/cp2/index.php?page=default&txt_teacher_name=foo
index.php
<?php
if (isset($_GET(txt_teacher_name)) {
//do db insert
}
?>
<form action = 'index.php' method = 'get'>
<input type = 'text' id = 'txt_teacher_name' name = 'txt_teacher_name' />
<input type = 'submit' value = 'Set' />
</form>
I have written this simple php code (see below). The problem is that when i try running this code, the form loads values into both the username and password input fields. I have tried setting autocomplete = "off" in both the form tag and the input tag as suggested here but it does not seem to work. My browser if firefox 38.0 for Ubuntu canonical 1.0. What is the problem here?
<?php
if (isset($_POST['submit']) && !empty($_POST['username']) && !empty($_POST['password'])){echo "yesu";
$username = $_POST['username'];
$password = md5 ($_POST['password'] . 'ijdb');
print "welcome $username";
/*header ('Location: .');
exit();*/
}
else{
?>
<form action = "" method = "post" autocomplete = "off">
Username: <input type = "text" name = "username" autocomplete = "off"/><p>
Password: <input type = "password" name = "password" autocomplete = "off"/><p>
<input type = "submit" name = "submit" value = "login"/>
<form>
<?php
}
?>
Put a hidden empty text field between username and password
<input type="text" name="username">
<input type="text" style="display:none">// like this
<input type="password" style="display:none">// Introducing this line ensures that whenever you load the form the password field is blank
<input type="password" name="password">
Explain
It will make the username text field not to show any previously typed
words in a drop down. Since there is no attribute like name, id for
the input field it wouldn't
send any extra parameters also.
Use placeholders
Username: <input type = "text" name = "username" placeholder = "username"/>
Password: <input type = "password" name = "password" placeholder = "password"/>
seems like some preset in your browser(check addons or whatever),
anyway if you wish to get rid of it - just use custom names for inputs, aka:
Username: <input type = "text" name = "uname" autocomplete = "off"/>
or
Username: <input type = "text" name = "something_unusual" autocomplete = "off"/>`
There are three things you can try:
<form autocomplete="off">
Ensure that when you are using autocomplete="off" that you an html5 declaration:
<!DOCTYPE html>
Lastly, it might also be browser settings remembers especially passwords and username combinations
I have this form html code in update.php. For updating, it's required to link to another page save_seeker.php with mysql update script for it to be executed. Is there any way to execute the script in same page on submitting form so that after query execution it remains on same page?
<form action= "save_seeker.php" method = "post">
Update details !<br><br>
First Name
<input type = "text" name = "fname" value = "<?php echo $disp['fname'];?>"><br><br>
Last Name
<input type = "text" name = "lname" value = "<?php echo $disp['lname'];?>"><br><br>
Contact number
<input type = "text" name = "contact" value = "<?php echo $disp['contact'];?>"><br><br>
Email-id
<input type = "email" name = "email" value = "<?php echo $disp['email'];?>"><br><br>
Address
<input type = "text" name = "address" value = "<?php echo $disp['address'];?>"><br><br>
Experience
<input type = "number" name = "experience" value = "<?php echo $disp['experience'];?> "><br><br>
Qualification
<input type = "text" name = "qualification" value = "<?php echo $disp['qualification'];?>"><br><br>
<input type = "Submit" value = "Update">
</form>
You could do the processing in the same file by adding this into the form action.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<!-- Input fields in here-->
<input type="submit" name="form_submit" value="Submit">
</form>
Now check for the submit action by checking if it is set in the post variable
<?php
if ( isset( $_POST['form_submit'] ) ) {
// Do processing here.
}
?>
You could use the include('page-with-update.php') , call the update function and use the $_SERVER["PHP_SELF"].
I hope helped!!
I am quite new at programming (especially in PHP).
Anyway, I have been attempting for a bit now to create a log-in page that utilizes both PHP and HTML.
The main idea is if it's the first time the user has come to the log-in page, then they have to click a "submit" button first; which will then reload the page but now will have a where the user will input information to call up another PHP script.
I have attempted the following codes to achieve this:
<form method = "post"
action = "Sign-In2.html">
<p>
<br />
<input type = "submit"
name = "returnUser"
value = "Click To Log In">
</P>
</form>
<?php
if (isset($_POST['returnUser'])) {
?>
<form method = "post"
action = "Login2.php">
<p>
<br />
In Honor Of:
<input type = "text"
name = "userName"
value = "">
<br />
EDGE Code:
<input type = "password"
name = "edgeCode"
value = "">
<br /><br />
<input type = "checkbox"
name = "rememberUser"
value = "remembered">Remember Me
<br />
<input type = "submit"
value = "Log Me In">
</p>
</form>
<?php
} else {
} //end if
?>
From everything I have read online (from this site and others), I am under the impression that my code includes two forms and a PHP "if" statement.
The FIRST form just provides a "submit" button that is named "returnUser" and reloads the page (which is named Sign-In2.html).
Then PHP jumps in and runs a condition check. If the "submit" button from the FIRST form has in fact been clicked, then the SECOND form will be run. If it has NOT been clicked, then nothing happens.
SO MY ISSUE is that when I run this this code from localhost WAMPserver, BOTH forms show up! I am unable to understand or find out why not just the first form but both are showing up when I load the page! I just want the first submit button to show up so I can click on it and refresh the page with the input fields from the second form :(
Any help would be highly appreciated!
Note: The second form and its phpscript both run no problem.
You want to display one form or the other, so use the if statement to choose which one you want to display. What your code is doing at the moment is displaying the first form - then if you have a $_POST value sent, displaying the second one.
Changing your code to the below will display one form or the other, depending on if the $_POST is set or not.
<?php
if (isset($_POST['returnUser']))
{
?>
<form method = "post"
action = "">
<p>
<br />
In Honor Of:
<input type = "text"
name = "userName"
value = "">
<br />
EDGE Code:
<input type = "password"
name = "edgeCode"
value = "">
<br /><br />
<input type = "checkbox"
name = "rememberUser"
value = "remembered">Remember Me
<br />
<input type = "submit"
value = "Log Me In">
</p>
</form>
<?php
}
else
{
?>
<form method = "post"
action = "">
<p>
<br />
<input type = "submit"
name = "returnUser"
value = "Click To Log In">
</P>
</form>
<?php
} //end if
?>
change the File name Sign-In2.html to Sign-In2.php and same in form action.
Is this by any chance a normal .html page?
By default, PHP doesn't run on those, so your <?php ?> tags are interpreted as normal HTML tags.
Change the file's extension to PHP to solve it.