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
    May 2008
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    $_POST['submit'] not getting set

    Hi there .
    I have a problem getting this code to work - it's a login page i'm making for a site - but for some reason it's not wroking .
    PHP Code:
    <?php

    require_once("functions.php");
    connection("localhost","abcd","%","logintest");

    if(isset(
    $_POST['submit'])) {$user=$_POST['user']; 
                                          
    $passw=$_POST['passw'];
                                 
                                              if(
    authorization($user,$passw)) {
                                        echo 
    "<center><h3><b>".$user."<br />Name and password OK . Access approved!</b></h3>
                                        <a href=\"sectionA.php\">Section A</a> | "
    ."<a href=\"sectionB.php\">Section B</a> | ".
                                        
    "<a href=\"logout.php\">Logout</a></center>";
                                        }
                            else { echo 
    "<center><hr>".$_POST['user']."<br />NAME OR PASS WRONG ACCESS DENIED!</hr></center>
                            <center><a href='"
    .$_SERVER['PHP_SELF']."'>Back</a>";
                            }
                }
    else {

    ?>

    <center><form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" > 
         <table>
         <tr>
         <td>Username</td><td><input type="text" name="user" /></td>
         </tr>
         <tr>
         <td>Password(case sensitive):</td>
         <td><input type="password" name="passw" /></td>
         </tr>
         <tr>
         <td><input type="reset" value="Reset values" /></td>
         <td><input type="submit"  /></td>
         </tr>
         </table>
         </form>
         </center>
         <?php
         
    }
         
    ?>
    This is the login page - if the form has not been submitted then it should displaya login form , which it does .When the submit button is pressed , the page should reload and display the links .However , it does not ... it reloads and it displays the form again .After some personal debugging attemps , I foudn out that the problem is the
    PHP Code:
    if(isset($_POST['submit'])) 
    part .If I insert an $aux or something equal to one there the page reloads but like this it does not work ...
    Also , here is the code for the functions I used :
    PHP Code:
    <?php
    session_start
    ();

    header("Cache-control: private");
    function 
    connection($host,$user,$passw,$db) {
                            
    $conn=mysql_connect($host,$user,$passw) or 
                            die(
    "Cannot establish connection");
                            
    mysql_select_db($db,$conn) or die("Cannot access database");
                            }
    function 
    authorization($user,$passw) {
                            
    $passw=md5($passw);
                            
    $rez=mysql_query("SELECT username,password FROM users WHERE username='$user' AND password='$passw'");
                            if(
    mysql_num_rows($rez)==1) {
                                  
    session_start();
                                  
    $_SESSION['user']=$user;
                                  
    $_SESSION['passw']=$passw;
                                  
    $_SESSION['id']=session_id();
                                  return 
    true;
                                  }
                    else return 
    false;
                    }
    function 
    authenthification() {
           if(
    $_SESSION['id']!=session_id()) {return false;}
                   else { 
    $rez=mysql_query("SELECT username,password FROM users WHERE username='".$_SESSION['user']."' AND password='".$_SESSION['passw']."'");
                   if(
    mysql_num_rows($rez)!=1)
                   return 
    false;
                   else
                   return 
    true;
                   }
    }
    ?>
    I'd be really grateful is somebody could tell me what the problem is ...

    I'm using PHP 5.2.5 MySQL server 5 on Apache 2.2 .
    Last edited by enaceo; 05-20-2008 at 07:43 PM.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Well gee wiz. The button has no name.

    You only have:
    Code:
    <input type="submit"  />

  • Users who have thanked kbluhm for this post:

    enaceo (05-20-2008)

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You need to name your form input(s).
    Code:
    <input type="submit" name="submit" value="Submit" />

  • Users who have thanked Inigoesdr for this post:

    enaceo (05-20-2008)

  • #4
    New to the CF scene
    Join Date
    May 2008
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Aaaah...i am really stupid.
    Thanks a lot for the help .Now it works .
    I was lookin through all my other files that used the same methods (with post) and i looked over the "<form .../>" line probably 100 times but I just didn't see the name was missing :|.
    Again , thanks for the pointer ... and a big "Duh!" to me ...

  • #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
    Is there any problem in using the name="submit" for a form element? I remeber a case where I was getting an error form.submit() is not a function, when I called the submit via javascript.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by abduraooft View Post
    Is there any problem in using the name="submit" for a form element? I remeber a case where I was getting an error form.submit() is not a function, when I called the submit via javascript.
    If you were using Javascript to submit the form it could be a problem. But this user isn't, and a lot of people probably won't.


  •  

    Posting Permissions

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