473,388 Members | 1,468 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,388 software developers and data experts.

Login Form (USERid, Password) getting error

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 2210
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=’$username’ and password=’$password’ ";

$result = mysql_query($query);

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

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

?>[/PHP]


ok try it and reply ..
Nov 21 '07 #2
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\login.php on line 15
Nov 21 '07 #3
This means that your sql query means line no 13
[PHP]$query = "SELECT * FROM users WHERE username=’$username’ and password=’$password’ "; [/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=’$username’ and password=’$password’ ";
$result = mysql_query($query);
$row = mysql_fetch_array($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\login.php on line 15
Nov 21 '07 #4
Hi priyakollu

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

Good day
Nov 21 '07 #5
Markus
6,050 Expert 4TB
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
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
after changing the code i still got an error


Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\sunkalpid\login.php on line 20
anyone plz help me
Nov 21 '07 #8
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_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\sunkalpid\login.php on line 20
anyone plz help me
Nov 21 '07 #9
Atli
5,058 Expert 4TB
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
after changing the code i still got an error


Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\sunkalpid\login.php on line 20
anyone plz help me
Hi Priya
Please check, If you have mentioned singles quotes ( ' ) arround $username and $password in line 18, i.e. where you are declaring the $query.

Yes, If The fields are numeric, then no need to do that.

Have a gooooooood day.
Nov 22 '07 #11

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

Similar topics

6
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...
5
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...
2
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...
7
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 ...
4
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...
12
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...
2
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...
13
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...
1
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...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.