473,466 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

User Authentication

14 New Member
Im trying to check a email address and password against those stored in a data base callled contactd, but i get the following error code:
Query failed. You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM contactd WHERE email = '' AND password = PASSW

Below is the code I cant figure out whats wrong anyhelp would be great,

[php] <?php
session_start();
include 'config.php';
include 'opendb.php';
$errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {

$userId = $_POST['txtUserId'];
$password = $_POST['txtPassword'];

// check if the user id and password combination exist in database
$sql = "SELECT $userId
FROM contactd
WHERE email = '$userId' AND password = PASSWORD('$password')";
//
$result = mysql_query($sql)
or die('Query failed. ' . mysql_error());

if (mysql_num_rows($result) == 1) {
// the user id and password match,
// set the session
$_SESSION['db_is_logged_in'] = true;

// after login we move to the main page
header('Location: main.php');
exit;
} else {
$errorMessage = 'Sorry, wrong user id / password';
}


}
?>
<?php include 'closedb.php'?>
<html>
<head>
<title>Basic Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
if ($errorMessage != '') {
?>
<p align="center"><strong><font color="#990000"><?php echo $errorMessage; ?></font></strong></p>
<?php
}
?>
<form action="" method="post" name="frmLogin" id="frmLogin">
<table width="400" border="1" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="150">User Id</td>
<td><input name="txtUserId" type="text" id="txtUserId"></td>
</tr>
<tr>
<td width="150">Password</td>
<td><input name="txtPassword" type="password" id="txtPassword"></td>
</tr>
<tr>
<td width="150">&nbsp;</td>
<td><input name="btnLogin" type="submit" id="btnLogin" value="Login"></td>
</tr>
</table>
</form>
<?php //include 'config.php'?>
<?php //include 'opendbc.php'?>
</body>
</html>


[/php]
Dec 11 '06 #1
2 982
kempy535
14 New Member
Doh sorted it I think. I wasnt thinking straight.
[php]$sql = "SELECT * FROM contactd WHERE email = '$userId' AND password = PASSWORD('$password'
[/php]
Dec 11 '06 #2
ronverdonk
4,258 Recognized Expert Specialist
Can happen to anyone.

Ronald :cool:
Dec 11 '06 #3

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

Similar topics

4
by: Tim Daneliuk | last post by:
OK, I've Googled for this and cannot seem to quite find what I need. So, I turn to the Gentle Geniuses here for help. Here is what I need to do from within a script: Given a username and a...
4
by: Dan Bart | last post by:
I am using an application which is a modification of IBuySpy Portal. It is using Forms authentication. Users login and their name is added to Context Then I use: ...
5
by: Matthew Louden | last post by:
I wrote ASP.NET application that access SQL Server database. When I run the application, it yields "Login failed for user '<COMPUTER_NAME>\ASPNET'" error message. I then did the following, but...
8
by: Joe | last post by:
I check for the NTLogin of a user by Page.User.Identity.Name, but when I put the app on the server the value for Page.User.Identity.Name is "" I had the <allow users="*/> attribute commented...
15
by: Tom Nowak | last post by:
I am writing a webapp in which a user is required to enter a login id and password on a login form. I have forms authenticaion coded in my web.config. Once the user is logged in, I want to use the...
1
by: noor | last post by:
hi, can any one tell me a javascript that can be called on mouseover event of a html link control . script can check from session either a user is login or not In the case of Login it will...
2
by: J | last post by:
Hello. I apologize if this isn't the appropriate group for this question but I was wondering if it's possible to allow regular windows domain users to change their passwords through an .asp page? ...
3
by: mario.colorado | last post by:
Hi! Does anyone know why it is that when I use: Request.LogonUserIdentity.User.ToString() I get something like: S-1-5-21-2268419..........
9
by: webrod | last post by:
Hi all, how can I check a user/password in a LDAP ? I don't want to connect with this user, I would like to connect to LDAP with a ADMIN_LOG/ADMIN_PWD, then do a query to find the user and...
6
by: MuZZy | last post by:
Hi, I am looking to find a way to get currently logged in user's object GUID without querying ActiveDirectory. For example, when i log in to my laptop from home, I'm not on the office network so...
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
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,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.