PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 2nd, 2013, 11:52 AM
southwind84 southwind84 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 southwind84 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 36 sec
Reputation Power: 0
Unhappy Always same result... Login failure

Hope someone can help me....
First of all sorry for my bad english!
I'm trying to write an php code for a user login.
When I run the code i always get the same result:"Login failure".
Even if thes "user" and "password" that i tiped in exists or not.
I used xampp 3.1.0, databasename: login, tablename: login.
Think about it for days but can't find any solution, please can someone help me? what i do wrong?
Here is the code:

<html>
<head >
<body>

<form action='login.php?login=yes' method=POST>
Username:<input type=text name='user' /><br />
Password: <input type=password name='pass' /> <br />
<input type=submit value='Go!' />
</form>

<?php

$user=isset($_POST['user']);
$pass=isset($_POST['pass']);
$login=isset($_GET['login']);

if($login=='yes')
{
$con=mysql_connect('localhost','root','root') or die("Cant connect host");
mysql_select_db('login') or die("Cant connect database");

$get=mysql_query("SELECT count(id) FROM login WHERE (user='$user' AND pass='$pass')") or die ("Error on mysql_querry");
$result=mysql_result($get,0);

if($result!=1) echo "Login failure!";
else {
echo "Login sucess!";
$_SESSION['user']=$user;
}

}
?>

</head>
</body>
</html>

Reply With Quote
  #2  
Old January 4th, 2013, 10:23 AM
Jyncka's Avatar
Jyncka Jyncka is offline
We're trapped inside a game!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Location: Maryland
Posts: 299 Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)  Folding Points: 37258 Folding Title: Starter FolderFolding Points: 37258 Folding Title: Starter Folder
Time spent in forums: 5 Days 9 h 30 m 29 sec
Reputation Power: 902
You have some syntax problems in your code. Please use code tags to format it in your post so everyone can read it more easily.

The error I see is this

Quote:
user='$user' AND pass='$pass'


The single quotes tell PHP to interpret those variables as strings. You are querying for rows where user has a value of "$user" and password has a value of "$pass". Try removing the single quotes.

Finally, this seems like it should be moved to the PHP board since it's a coding error.
__________________
"Those who can make you believe absurdities can make you commit atrocities."

Reply With Quote
  #3  
Old January 4th, 2013, 11:10 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 43rd Plane (26000 - 26499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,443 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 14 h 22 m 31 sec
Reputation Power: 4141
Quote:
Originally Posted by Jyncka
The single quotes tell PHP to interpret those variables as strings.
actually, those single quotes are for mysql, not for php, but yes, they delimit strings

if you remove them, you will have an sql statement that says
Code:
WHERE (user=fred AND pass=sesame)
and at that point, mysql interprets fred and sesame as column names, resulting in an error

the only time the quotes are not required is when the columns are numeric and the values are numbers
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Always same result... Login failure

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap