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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    PHP-Multiple Submit Buttons on Page Problem

    I am using the following code for this issue and it doesn't do anything. I select the button to Create User and I stay on the same page. What should be happening is that a form which is built on createUserAccount.php. Can anyone give me direction as I really need to get this project completed so I can get a new, better paying job? Thank you.

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <?php
    if(isset($_POST['submit1']))
    {
    header("Location: createUserAccount.php");
    }
    else if(isset(
    $_POST[["submit2"]))
    {
    header("Location: loginUser.php");
    }
    ?>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Create User-Login Functions</title>

    <![endif]--></head>

    <body class="thrColElsHdr">
    <div id="container">
    <div id="header">

    <!-- end #header --></div>

    <div id="sidebar1">

    <!-- end #sidebar1 --></div>

    <div id="sidebar2">
    <ul>
    <li><a href="index.html">Home</a></li>
    <li><a href="about.html">About Us</a></li>
    <li><a href="tkdHistory.html">TaeKwonDo History</a></li>
    <li><a href="blackbelts.html">Blackbelts</a></li>
    <li><a href="contact.html">Contact Us</a></li>
    <li><a href="adminFunctions.php">Administration Functions</a></li>
    <li><a href="createUserLoginFunctions.php">Create User-Login Functions</a></li>
    </ul>
    <!-- end #sidebar2 --></div>

    <div id="mainContent">
    <form id="createUserLoginFunctions" name="createUserLoginFunctions" method="post" action="">
    <br />
    <label>Create New User Account </label>
    <input type="submit" name="submit1" value="CREATE USER">
    <br />
    <br />
    <label>Login User </label>
    <input type="submit" name="submit2" value="LOGIN USER">
    <br />
    <br />
    </form>

    <!-- end #mainContent --></div>
    <br class="clearfloat" />

    <div id="footer">

    <!-- end #footer --></div>
    <!-- end #container --></div>
    </body>
    </html>
    Last edited by guelphdad; 08-03-2012 at 02:26 PM. Reason: edited code tags to php tags

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,854
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <?php
    if(isset($_POST['submit1']))
    {
    header("Location: createUserAccount.php");
    }
    else if(isset(
    $_POST[["submit2"]))
    {
    header("Location: loginUser.php");
    }
    ?>
    Quote Originally Posted by http://php.net/header
    Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
    Move your DOCTYPE to the immediate top of
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I made the change and it hasn't made any difference...the same thing is happening. It stays on the page and not moving to the form.

  • #4
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Please make sure you post in the correct forums. your thread has nothing to do with mysql. Thread moved to PHP forum.

  • Users who have thanked guelphdad for this post:

    kccagal (08-03-2012)

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Quote Originally Posted by kccagal View Post
    PHP Code:
    <?php
    if(isset($_POST['submit1']))
    {
    header("Location: createUserAccount.php");
    }
    else if(isset(
    $_POST[["submit2"]))
    {
    header("Location: loginUser.php");
    }
    ?>
    For simplicities sake, it's better to give all of your buttons the same name when they're in the same form:

    Code:
    <input type="submit" name="mode" value="Create User">
    <input type="submit" name="mode" value="Login User">
    PHP Code:
    <?php

    if (!isset($_POST['mode']))
       {
       
    //Exit or error here
       
    }

    switch (
    strtolower($_POST['mode']))
       {
       case 
    'create user':
          
    //Your code here
       
    break;
       case 
    'login user':
          
    //Your code here
       
    break;
       }
    ?>
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    kccagal (08-04-2012)

  • #6
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you all for your assistance. I am a student just trying to get this project completed.


  •  

    Posting Permissions

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