473,385 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 1927
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.