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
    Feb 2010
    Posts
    81
    Thanks
    23
    Thanked 0 Times in 0 Posts

    My form goes back to the home page!

    G'day guys,

    I have created a form inside the admin section of my website that inserts data into mysql.. and works a charm (its an account creation form). The only problem is that once I press submit it logs me out and returns to the home page of my web app.

    So for example the url for the section i am in is: www.website.com/index.php?m=admin&view=create

    when I press submit it takes me back to: index.php.

    The code for the form is as follows, if that helps:
    PHP Code:
    <?php
    if($_POST["username"]) {
        
    $connection db_connect();    
        
    extract($_POST);
        
    mysql_query("INSERT INTO `".$type."`".
                    
    "(`username`, `first_name`, `last_name`, `password`,".
                    
    "`email`, subjects".
                    
    ") VALUES(".
                    
    "'$username', '$first_name','$last_name', '$password',".
                    
    "'$email', '$subjects')") or die(mysql_error());    
    }
    ?>
    <form id="form1" name="form1" method="post" action="#">
     
    <table width="465" border="0" align="center">
    <tr>
    <td colspan="2"><p><strong>Administration Creation Tool</strong></p>
    <p><em>This allows you to add more users to your website.</em></p>
    <p>&nbsp;</p></td>
    </tr>
    <tr>
    <td width="165"><label>Username:</label></td>
    <td width="290"><input name="username" type="text" id="username" size="35" /></td>
    </tr>
    <tr>
    <td>First Name:</td>
    <td><input name="first_name" type="text" id="first_name" size="35" /></td>
    </tr>                      
    <tr>
    <td>Last Name:</td>
    <td><input name="last_name" type="text" id="last_name" size="35" /></td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><input name="password" type="password" id="password" size="35" /></td>
    </tr>
    <tr>
    <td><label>Email Address:</label></td>
    <td><input name="email" type="text" id="email" size="35" /></td>
    </tr>
    <tr>
    <td>Account Type:</td>
    <td><select name="type" id="type">
    <option value="admins" selected="selected">Web Administrator</option>
    <option value="teachers">Teacher</option>
    <option value="students">Student</option>
    <option value="parents">parents</option>
    </select></td>
    </tr>
    <tr>
    <td>Subjects (<strong><em>teachers Only</em></strong>)</td>
    <td><label>
    <textarea name="subjects" cols="35" rows="5" id="subjects">ie. SUB1A,SUB1B</textarea>
    </label></td>
    </tr>
    <tr>
    <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
    <td colspan="2"><div align="center">
    <input type="submit" name="submit" id="submit" value="Submit" />
    </div></td>
    </tr>
    </table>
    </form>
    Please note: I have also tried putting in different things into ACTION in the form header (ie. #, the page itself, etc)

    Anyhelp would be greatly appreciated!

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,497
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    So what you're showing us in post #1 is only a small section of the whole script?
    You mention you're only showing us the form? is that correct?

    What about the rest of it?

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    278
    Thanks
    78
    Thanked 2 Times in 2 Posts
    Lol, I dont think this will fix it but I dont see anything wrong. But, in my forms I put the <table></table> outside of the <form></form> idk

  • #4
    New Coder
    Join Date
    Feb 2010
    Posts
    81
    Thanks
    23
    Thanked 0 Times in 0 Posts
    This form works fine, the only problem is that on submit it returns home. This is a form in my admin section.. I didn't include the other code as I wouldn't think it has anything relevant to this..

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    So for example the url for the section i am in is: www.website.com/index.php?m=admin&view=create
    Try changing the action of that form to
    Code:
    <form id="form1" name="form1" method="post" action="index.php?m=admin&view=create">
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    New Coder
    Join Date
    Feb 2010
    Posts
    81
    Thanks
    23
    Thanked 0 Times in 0 Posts
    Thanks for your replies, I am going to try a few things.. I will keep you posted!

    PS. Putting in the URL in the ACTION doesnt work either

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,497
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    The script you showed us in post #1 has nothing wrong with it,
    so the problem has to be in the "rest of the script". You'll have to
    show us all of it ... and just remove any user or password (sensitive information).

  • #8
    New Coder
    Join Date
    Feb 2010
    Posts
    81
    Thanks
    23
    Thanked 0 Times in 0 Posts
    The website is modular.. There is an admin module which the application hits controller.php (which contains the switches and cases to point the request in the right direction).

    I have added a switch in their called password which points it to the password form I have displayed above.

    Here is the controller.php:
    PHP Code:
    <?php
    //no direct access
    defined'_OS' ) or die( 'Restricted access' );
    check_authentication('admins');
    // Including the Model for The pages.
    include_once(MODULES_PATH.'admin/models/install.php');
    include_once(
    MODULES_PATH.'admin/models/settings.php');
    //Getting params
    $action $_GET['action'];
    if(!
    $id)
    {
    $id $_GET['id'];}
    if(!
    $view)
    {
    $view $_GET['view'];} 
    if(!
    action)
    {;}
    //Switching with the view
    switch ($view)
    {
     case 
    "modules":
     {
     switch (
    $action)
      {
      case 
    "list":
      
    $module list_modules();
      include(
    MODULES_PATH.'admin/views/modules/list.php');
      break;
      case 
    "install":
      include(
    MODULES_PATH.'admin/views/modules/install.php');
      break;
      case 
    "uninstall":
      if(
    uninstall_module($id))
      {echo 
    'Module Uninstalled';}
      break;
      }
     }
     break;
     case 
    "settings":
     {
     
    $admin get_admin();
     include(
    MODULES_PATH.'admin/views/settings/settings.php');
     break;
     }
     break;
     case 
    "password":
     {
     
    $admin get_admin();
     include(
    MODULES_PATH.'admin/views/settings/password.php');
     break;
     }
    }
    ?>

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,497
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    It looks like "view" has to be one of these three: module, settings, password

    If "view" is equal to "module", then "action" needs to be: list, install or uninstall

    So I would expect the URL to be like:
    <form id="form1" name="form1" method="post" action="index.php?view=module&action=create">

    BUT ... there is no "create" ... action can only be list, install or uninstall.
    I don't see anything in the switch commands for "create". It's like something is missing.


  •  

    Posting Permissions

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