472,373 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 software developers and data experts.

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 1892
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,658 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

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

Similar topics

1
by: Chip | last post by:
I am trying to get sessions to work on a log in screen to give certain users access to certain pages/directories. The problem is that when the login button is pushed (or the enter key pressed) the...
0
by: Dan | last post by:
hi ng, is there a way to set a custom login failed page when using windows authentification? my settings are: --------------------- <authorization> <allow users="x,y,z" /> <deny users="*"...
6
by: BizWorld | last post by:
Hi, I have a scenario where i need to configure only Login.aspx page to use SSL. All other application will run on HTTP protocol. If someone can guide me how to accomplish this. One of my idea...
3
abdoelmasry
by: abdoelmasry | last post by:
Hi Friends i need help in sessions im passing variables between pages using sessions this is the main page thats mean the home page the main page have table to show messages for users , it have...
3
by: wesomon99 | last post by:
I have a .jsp page with a button that is supposed to forward the current HTTP session to a new page (performing the same function as a form submit button, except without creating a new session). The...
1
LeoTD
by: LeoTD | last post by:
Dear all, I'm a newbiew in Curl functions. I want to transfer Session data from this page to another in difference server. It means: page1 have a link to page 2. When i click to link in page 1,...
3
by: Andy B | last post by:
How do you rename the login.aspx page and still make it work? and How would you determine what you should rename it to?
9
by: Josh | last post by:
I run a Joomla website and am familiar with php in some but not all aspects. Currently I am trying to find some solutions related to session handling. Am I correct in saying that "login" is kept...
0
by: chet | last post by:
We have a number of existing asp.net applications where our clients now want to content manage the login page. The applications have not been developed with content management in mind and its...
3
by: Michaeloco | last post by:
Hello, I am using the built in membership provider with vwd. On login i want to add a custom session object from a UserData table in my sql database to session on login to be used on all pages of...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.