Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-26-2012, 01:29 PM   PM User | #1
ThunderWaffe
New Coder

 
Join Date: Sep 2012
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
ThunderWaffe is an unknown quantity at this point
Question 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:

<input type="submit" name="submit" title="Login"/>

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..
ThunderWaffe is offline   Reply With Quote
Old 09-26-2012, 07:42 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,604
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
This is not an HTML/CSS issue, it’s done with a PHP location header.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 09-26-2012, 08:46 PM   PM User | #3
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
What code do you have so far? Forms and redirects are a staple of PHP, and countless tutorials are available for this online.
Keleth is offline   Reply With Quote
Old 09-26-2012, 11:24 PM   PM User | #4
ThunderWaffe
New Coder

 
Join Date: Sep 2012
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
ThunderWaffe is an unknown quantity at this point
Quote:
Originally Posted by Keleth View Post
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?

Thanks,
Thunder
ThunderWaffe is offline   Reply With Quote
Old 09-27-2012, 04:07 AM   PM User | #5
ThunderWaffe
New Coder

 
Join Date: Sep 2012
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
ThunderWaffe is an unknown quantity at this point
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!

Please help!

Thanks,
Thunder
ThunderWaffe is offline   Reply With Quote
Old 09-27-2012, 04:55 AM   PM User | #6
ThunderWaffe
New Coder

 
Join Date: Sep 2012
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
ThunderWaffe is an unknown quantity at this point
Here's the code I am using:

//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]')";

mysql_query($sql,$con);

mysql_close($con);
}
?>
ThunderWaffe is offline   Reply With Quote
Old 10-10-2012, 09:29 AM   PM User | #7
ThunderWaffe
New Coder

 
Join Date: Sep 2012
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
ThunderWaffe is an unknown quantity at this point
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!
ThunderWaffe is offline   Reply With Quote
Old 10-10-2012, 09:56 AM   PM User | #8
ThunderWaffe
New Coder

 
Join Date: Sep 2012
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
ThunderWaffe is an unknown quantity at this point
All fixed. I used:


PHP Code:
   if(isset($your_set_values)
    {
         
header("Location:index.php");
    } 
My code:

PHP Code:
<?php
if (isset($_POST['submit'])){
header("Location:myfilehere.php");

$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]')";

mysql_query($sql,$con);

mysql_close($con);
}
?>
ThunderWaffe is offline   Reply With Quote
Old 10-10-2012, 04:22 PM   PM User | #9
WingTsun
New Coder

 
Join Date: Jan 2012
Location: Latvia
Posts: 65
Thanks: 8
Thanked 2 Times in 2 Posts
WingTsun is an unknown quantity at this point
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
WingTsun is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:14 AM.


Advertisement
Log in to turn off these ads.