473,800 Members | 2,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Login Form (USERid, Password) getting error

9 New Member
hi guyz!
please help me in sorting out error as im unable to find it...
my requirement is there will be userid field and password field and "login" button after clicking button certain validations must be done whether he is an valid user or not (connect to database and check for valid user & password) if he is valid user he must login and goto another php file.....

im using winxp OS / XAMPP Windows Version 1.6.4 !

Problem: im getting errors im sending the errors & code plz sort out

Expand|Select|Wrap|Line Numbers
  1. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\sunkalpid\login.php:8) in C:\xampp\htdocs\sunkalpid\login.php on line 9
  2.  
  3. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\sunkalpid\login.php:8) in C:\xampp\htdocs\sunkalpid\login.php on line 9
  4.  
  5. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\sunkalpid\login.php on line 24

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Untitled Document</title>
  4. </head>
  5.  
  6. <body>
  7.  
  8. <?php
  9. session_start();
  10.  
  11. //Connect to database
  12.  
  13. mysql_connect ( "localhost", "root", "sunkalpid")or die("Could not connect: ".mysql_error());
  14. mysql_select_db("emp") or die(mysql_error());
  15.  
  16.  
  17. $username = $_POST['username'];
  18. $password = md5($_POST['password']);
  19.  
  20. $query = "SELECT * FROM  users WHERE username=’$username’ and password=’$password’ ";
  21.  
  22. $result = mysql_query($query);
  23.  
  24. if (mysql_num_rows($result) != 1) 
  25.     {
  26. $error = "Bad Login";
  27.     include "login.html";
  28.  
  29. } else {
  30.     $_SESSION['username'] = "$username";
  31.     include "registerdisplay.html";
  32. }
  33.  
  34. ?>
  35.  
  36.  
  37. </body>
  38. </html>
  39.  
looking forward ur help ASAP
Regards
Priya.
Nov 21 '07 #1
10 2252
robin1983
99 New Member
Hi Priya,
I think the problem is in the first line of php. means u start the session() before. do one think, just cut that protion of session start() from the begining and paste to else part just before u assign the $SESSION['username'] = $username; ok i think it will work.
[PHP]<?php
//session_start() ; remove this line from here

//Connect to database

mysql_connect ( "localhost" , "root", "sunkalpid" )or die("Could not connect: ".mysql_error() );
mysql_select_db ("emp") or die(mysql_error ());


$username = $_POST['username'];
$password = md5($_POST['password']);

$query = "SELECT * FROM users WHERE username=’$user name’ and password=’$pass word’ ";

$result = mysql_query($qu ery);

if (mysql_num_rows ($result) != 1)
{
$error = "Bad Login";
include "login.html ";

} else {
session_start() ;
$_SESSION['username'] = "$username" ;
include "registerdispla y.html";
}

?>[/PHP]


ok try it and reply ..
Nov 21 '07 #2
priyakollu
9 New Member
After placing tht session_start() ;
in else part i got this error

Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs \sunkalpid\logi n.php on line 15
Nov 21 '07 #3
robin1983
99 New Member
This means that your sql query means line no 13
[PHP]$query = "SELECT * FROM users WHERE username=’$user name’ and password=’$pass word’ "; [/PHP]
be sure that the username and password match the value in database. The error is because, the query dont get the result, thats why its giving this error. ok to check the error do one thing,
[PHP]
/// more code
$query = "SELECT * FROM users WHERE username=’$user name’ and password=’$pass word’ ";
$result = mysql_query($qu ery);
$row = mysql_fetch_arr ay($result) or die(mysql_error ());
echo $row['username']; // its just cheking the query giving the result or not ok ;
.. more code to write..
[/PHP]

when the query get the result, the error will automtically rectified. ok
After placing tht session_start() ;
in else part i got this error

Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs \sunkalpid\logi n.php on line 15
Nov 21 '07 #4
Ranjan kumar Barik
95 New Member
Hi priyakollu

The session_start() must be the the 1st statement of the page.

Good day
Nov 21 '07 #5
Markus
6,050 Recognized Expert Expert
Adding to the above post - move the session start to the very begging of that html file i.e. before the <html> before the <!DOCTYPE, before everything!

:)
Nov 21 '07 #6
Ranjan kumar Barik
95 New Member
Hi
I have modified your code a little bit.
Please check it out.
Expand|Select|Wrap|Line Numbers
  1. <?
  2. session start();
  3. ?>
  4. <html>
  5. <head>
  6. <title>Untitled Document</title>
  7. </head>
  8. <body>
  9. <?
  10. extract($_POST);
  11. $username = (isset($_POST['username']))?$_POST['username']:'';
  12. $password = (isset($_POST['password']))?$_POST['password']:'';
  13.  
  14. //Connect to database
  15. $conn = mysql_connect ( 'localhost', 'root', 'sunkalpid')or die("Could not connect: ".mysql_error());
  16. mysql_select_db('emp', $conn) or die(mysql_error());
  17.  
  18. $query = "SELECT * FROM  users WHERE username=’$username’ and password=’$password’ ";
  19.  
  20. $res = mysql_fetch_assoc(mysql_query($query, $conn));
  21.  
  22. if (!$res) 
  23.     {
  24. $error = "Bad Login";
  25.     include "login.html";
  26.  
  27. } else {
  28.     $_SESSION['username'] = "$username";
  29.     include "registerdisplay.html";
  30. }
  31.  
  32. ?>
  33.  
  34.  
  35. </body>
  36. </html>
Nov 21 '07 #7
priyakollu
9 New Member
after changing the code i still got an error


Warning: mysql_fetch_ass oc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs \sunkalpid\logi n.php on line 20
anyone plz help me
Nov 21 '07 #8
robin1983
99 New Member
Hi priya, just do one think, show ur html file too. ok the problem is at line no 18 ok.
after changing the code i still got an error


Warning: mysql_fetch_ass oc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs \sunkalpid\logi n.php on line 20
anyone plz help me
Nov 21 '07 #9
Atli
5,058 Recognized Expert Expert
Hi Priya.

Do not double post your questions. I have merged your two identical threads into this one thread.
Please read the Posting Guidelines before posting!

Also, please use [code] tags when posting your code examples. (See How to ask a question)

[code=php] ...PHP code goes here... [/code]

Thank you.

P.S. I edited out quotes from a couple of replies, where the poster quoted the entire first post. I hope you don't mind. It was making the thread unnecessarily long.
Nov 21 '07 #10

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

Similar topics

6
2757
by: josephrthomas | last post by:
hi..i am trying to make a login page and i am using access table.. when the user enters his userid and password i want to check the password from the table.. if any user with the userID that is entered exists i want to find the correspoding password for him else i want to throw an error saying no such user exists.. i know how to access the MS Access table and stuff..but
5
2638
by: calaha | last post by:
Hi all, I have been working with this since last night, and can't quite figure out why it's not working. I have a simple login box form that is set to be my startup form in my Access app (upon successful authentication, it opens the Switchboard). All it does is get the username and password, pull up a recordeset of the usernames and sets the UserId to be used throughout the session. The table Userlist is a SQL 2000 linked table. I can...
2
5167
by: MUHAMAMD SALIM SHAHZAD | last post by:
dear respected gurus, I would like to share ideas...as i learned from you and wish to tell that i had developed the system where i can audit each and every users and their actions(like add/edit/save/cancel/unco) =======================start of modules======================================= Option Compare Database Option Explicit
7
1539
by: Cemal Karademir | last post by:
Hi, I'm workin on a small Login page/program with asp.net. It uses an MS-Access database that looks like this: USERID | NAME | PASSWORD _________________________________ 1 | John | hello 2 | Paul | hello2 I don't understand why it doesn't work. I think i'm doing something wrong
4
1434
by: Joe | last post by:
Hi, I have MS Access database with a small table that has four columns ID (Primary Key), page, userid and password. The page column holds the name of the page which has the login form. The userid and password column contain the id and password that I am trying to check. You might wonder why I don’t have only two columns, userid and password. I intend to use this database for several different login pages. For a particular login page,...
12
6580
by: Michael | last post by:
Please Help me. I've got a .Net 2003 program that attaches to a SQL Server machine and I'm getting the above error when a user tries to log in. The SQL server is setup to use Windows Auth. and I have added the new user to the database and have given the user access to the database for the app. But everytime I try and login using this users ID, I always get the error: Login failed for user Christian.Gaut If I login using my userid and...
2
3688
by: Shakun | last post by:
Hi All, This is my 1st posting to this group. Can any1 help me with the "Remember Me" which is there in a login form. Im pasting the code below. Im not able to set a cookie.. Thanks, Shakun Vohra
13
3256
JodiPhillips
by: JodiPhillips | last post by:
G'day, I have a silly and simple problem that I need some guidance with. Due to the way our network is set up, I am unable to use the group permissions for Access and have had to implement log in procedures via a log in table within the database. This works fine. I have now expanded this table to include further data about the authorised user – Power User, Team Leader, & Facilitator. Depending on the user’s status as to which one of...
1
3319
by: Adrock952 | last post by:
I have a link on my site which obviously says "Login" where users log in. I would like that link to be changed to "Logout" when the user has successfully logged in and the session has been created and when the user logs out, i would like the link changed back to "Login" without having to refresh the page. here is my login page <?php if (is_authed_user()) { print ('You are already logged in, <a href="index.php">click here</a> to...
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10507
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10279
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9092
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7582
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.