Form Is Submitted And Page Redirects To Another Page
I'm still in need of help! It's the last thing I need for my website to be opened! Please read this and the edit! I will change the title to resolved when it's finished! Thanks!
Hey, I'm currently having trouble with something and I've tried a lot and I can't get it to work. This is what I need:
I've made a login form and I have a mysql database. I use the form code:
<form action="login.php" method="post">
If I do this, when the user hits "submit" it reloads the page and inserts the data into the database. I use this for the submit button:
What I need is when they click "submit" it inserts the information into the database and redirects them to another page "attentionError.php".
If you can help me that would be great.
Thanks,
Thunder
*EDIT* I was told this is not an html option. It is done with PHP. Someone posted that there are multiple tutorials online for this but I just don't know where to find or how to operate it. Most of the tutorials just redirect the page as soon as you go to the link. I want it so when they click "submit" the <input type="submit" /> that the information is sent to the database and the page forwards to another page (such as ones saying "you have logged in successfully but without having to use echo). *EDIT*
Last edited by ThunderWaffe; 09-27-2012 at 12:24 AM..
What code do you have so far? Forms and redirects are a staple of PHP, and countless tutorials are available for this online.
That's what I don't understand. I'm new to PHP and I've been using ASP. Would you mind finding a tutorial for something like this or explain how it is worked?
If anyone knows of a tutorial or knows how to do it (even if you don't know exactly) please post! I'm desperate for answers! I've been searching all night and I can't find a thing for exactly this I want!
//sends form to login.php and sends to mysql. If I change it to errorAttention.php (the site I want) it works how I want but the form data doesn't get sent to my mysql <form action="login.php" method="post">
<span class="inputLabel FlatHeader">Login:</span>
<div class="DarkInputBoxWrapper">
<div class="InputBoxLeft"><input type="text" title="Login" name="username" maxlength="200" size="26" value="" id="username" class="NoPlaceholder" ></div>
<div class="InputBoxRight"></div>
</div>
<span class="inputLabel FlatHeader">Password:</span>
<div class="DarkInputBoxWrapper">
<div class="InputBoxLeft"><input type="password" title="Password" name="password" maxlength="20" size="26" value="" id="password" class="NoPlaceholder" ></div>
<div class="InputBoxRight"></div>
</div>
//submit button below. I want it to submit the data and basically have a link to another page. <span class="Button Button29" id="modalLoginButton"><span><span><span class=""><b>Login</b></span><input type="submit" name="submit" title="Login"/></span></span></span>
<a class="PasswordLink" href="*******.php" target="_parent">Forgot Password?</a>
</form>
<?php
if (isset($_POST['submit'])){
$con = mysql_connect("*********","**********","***********");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("**********",$con);
$sql = "INSERT INTO users (Username,Password) VALUES ('$_POST[username]','$_POST[password]')";
I tried avoiding this the last time I needed it done. Now I need it again so I do need some help with this! Please, if you have a slight idea how to, please comment!
In your example, you are redirecting before the Database queries are executed. You should use the redirect at the end of your PHP Script.
__________________ "Be formless... shapeless, like water. Now you put water into a cup, it becomes the cup. You pour water into a bottle; it becomes the bottle. You put water into a teapot; it becomes the teapot. Now water can flow, or creep or drip or crash! Be water, my friend..." by Bruce Lee