469,328 Members | 1,265 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

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

This is admin.php

Expand|Select|Wrap|Line Numbers
  1. <form action="action/index.php" method="post"><table width="40%" border="0" cellspacing="0" cellpadding="0" align="center">
  2.   <tr>
  3.     <td height="20" width="9"><img src="http://example.com/submit/images/001.jpg" width="9" height="20"></td>
  4.     <td align="center" bgcolor="#B1D476" class="heading">Admin Login</td>
  5.     <td height="20" width="9" align="right"><img src="http://example.com/submit/images/002.jpg" width="9" height="20"></td>
  6.   </tr>
  7.   <tr>
  8.     <td background="../images/5.png" valign="baseline" style="background-repeat:repeat-y;background-position:left;" width="7">&nbsp;</td>
  9.     <td><table width="100%" border="0" cellspacing="2" cellpadding="2">
  10.       <tr>
  11.         <td class="links">Username</td>
  12.         <td><input name="textfield" type="text" class="short_text" /></td>
  13.       </tr>
  14.       <tr>
  15.         <td class="links">Password</td>
  16.         <td><input name="textfield2" type="password" class="short_text" /></td>
  17.       </tr>
  18.       <tr>
  19.         <td colspan="2" align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="Submit" value=" Login " /></td>
  20.       </tr>
  21.     </table></td>
  22.     <td background="../images/5.png" align="right" style="background-repeat:repeat-y;background-position:right;" width="7">&nbsp;</td>
  23.   </tr>
  24.   <tr>
  25.     <td height="7" width="7"><img src="http://example.com/submit/images/4.gif" width="9" height="7"></td>
  26.     <td valign="bottom" style="background-repeat:repeat-x;background-position:bottom;" background="../images/5.png"></td>
  27.     <td height="7" width="7"><img src="http://example.com/submit/images/3.gif" width="9" height="7"></td>
  28.   </tr>
  29. </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

Expand|Select|Wrap|Line Numbers
  1. <?  session_start();
  2.     include "../../conn.php";
  3.     if(isset($_REQUEST['Submit']))
  4.     {
  5.         $sql=mysql_query("select * from user where username='".$_REQUEST['textfield']."' and password='".md5($_REQUEST['textfield2'])."'");
  6.         header("location:../menu.php");
  7.     }    
  8. ?>
whether i need to change any codes in this or else in php my admin
Oct 16 '10 #1
4 1833
it seems you are wrong on this part ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. $sql=mysql_query("select * from user where username='".$_REQUEST['textfield']."' and password='".md5($_REQUEST['textfield2'])."'");
  3.  
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)
Expand|Select|Wrap|Line Numbers
  1. include "../../conn.php";
  2.  
  3. $sql="SELECT * FROM user WHERE (username = '".$_POST['textfield']."') AND (password = '".md5($_POST['textfield2'])."')";
  4. $n = mysql_num_rows($sql);
  5. if ($n == 1){ 
  6.     $_SESSION['username'] = $_POST['username'];
  7.     header("location:menu.php");
  8. }
  9. header("location:admin.php");
  10.  
Oct 27 '10 #2
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.
Oct 28 '10 #3
Dormilich
8,651 Expert Mod 8TB
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.
Oct 29 '10 #4
i need to redirect to tht page after entering id n password..
Oct 29 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by BizWorld | last post: by
3 posts views Thread by Andy B | last post: by
9 posts views Thread by Josh | last post: by
reply views Thread by chet | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.