Why sessions aren't working on a php login page for admins

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jagadeeshpark
    New Member
    • Oct 2010
    • 3

    Why sessions aren't working on a php login page for admins

    This is admin.php

    Code:
    <form action="action/index.php" method="post"><table width="40%" border="0" cellspacing="0" cellpadding="0" align="center">
      <tr>
        <td height="20" width="9"><img src="http://example.com/submit/images/001.jpg" width="9" height="20"></td>
        <td align="center" bgcolor="#B1D476" class="heading">Admin Login</td>
        <td height="20" width="9" align="right"><img src="http://example.com/submit/images/002.jpg" width="9" height="20"></td>
      </tr>
      <tr>
        <td background="../images/5.png" valign="baseline" style="background-repeat:repeat-y;background-position:left;" width="7">&nbsp;</td>
        <td><table width="100%" border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td class="links">Username</td>
            <td><input name="textfield" type="text" class="short_text" /></td>
          </tr>
          <tr>
            <td class="links">Password</td>
            <td><input name="textfield2" type="password" class="short_text" /></td>
          </tr>
          <tr>
            <td colspan="2" align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="Submit" value=" Login " /></td>
          </tr>
        </table></td>
        <td background="../images/5.png" align="right" style="background-repeat:repeat-y;background-position:right;" width="7">&nbsp;</td>
      </tr>
      <tr>
        <td height="7" width="7"><img src="http://example.com/submit/images/4.gif" width="9" height="7"></td>
        <td valign="bottom" style="background-repeat:repeat-x;background-position:bottom;" background="../images/5.png"></td>
        <td height="7" width="7"><img src="http://example.com/submit/images/3.gif" width="9" height="7"></td>
      </tr>
    </table></form>
    ----------------------------------
    when i click submit button it want check this code and need to return menu.php , but it goes to same admin.php

    below file name is action/index.php

    Code:
    <?  session_start();
    	include "../../conn.php";
    	if(isset($_REQUEST['Submit']))
    	{
    		$sql=mysql_query("select * from user where username='".$_REQUEST['textfield']."' and password='".md5($_REQUEST['textfield2'])."'");
    		header("location:../menu.php");
    	}	
    ?>
    whether i need to change any codes in this or else in php my admin
    Last edited by Dormilich; Nov 2 '10, 07:36 AM. Reason: please use [CODE] [/CODE] tags when posting code
  • Reza Ruslan

    #2
    it seems you are wrong on this part ...

    Code:
    $sql=mysql_query("select * from user where username='".$_REQUEST['textfield']."' and password='".md5($_REQUEST['textfield2'])."'");
    you should use POST instead REQUEST, because you'll send the data and not request the data (CMIIW), and please add "()" to use WHERE command with $_POST func..

    plus.. to meet the false or true condition,, use "if" function and do comparison condition with mysql_num_rows function to retrieves the number of rows from a result set($sql).. as result.. define the header location...

    let me show you an ex. (untested)
    Code:
    include "../../conn.php";
    
    $sql="SELECT * FROM user WHERE (username = '".$_POST['textfield']."') AND (password = '".md5($_POST['textfield2'])."')";
    $n = mysql_num_rows($sql);
    if ($n == 1){ 
        $_SESSION['username'] = $_POST['username'];
        header("location:menu.php");
    }
    header("location:admin.php");

    Comment

    • jagadeeshpark
      New Member
      • Oct 2010
      • 3

      #3
      Thanks for your reply Reza Ruslan,
      Could you please provide me the code for test one , because i try to use your code also but its getting an error.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        when i click submit button it want check this code and need to return menu.php , but it goes to same admin.php
        out of interest, why would you want that particular page?

        EDIT: confusion has been cleared, so the question is obsolete.
        Last edited by Dormilich; Nov 2 '10, 07:38 AM.

        Comment

        • jagadeeshpark
          New Member
          • Oct 2010
          • 3

          #5
          i need to redirect to tht page after entering id n password..

          Comment

          Working...