Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,475
    Thanks
    6
    Thanked 980 Times in 953 Posts
    This is not an HTML/CSS issue, it’s done with a PHP location header.

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    What code do you have so far? Forms and redirects are a staple of PHP, and countless tutorials are available for this online.

  • #4
    New Coder
    Join Date
    Sep 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #5
    New Coder
    Join Date
    Sep 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    New Coder
    Join Date
    Sep 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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);
    }
    ?>

  • #7
    New Coder
    Join Date
    Sep 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #8
    New Coder
    Join Date
    Sep 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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);
    }
    ?>

  • #9
    New Coder
    Join Date
    Jan 2012
    Location
    Latvia
    Posts
    65
    Thanks
    8
    Thanked 2 Times in 2 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •