Solved

PHP simple mysql login - can't find the problem

Posted on 2012-04-03
3
240 Views
Last Modified: 2012-04-03
I"m trying to do a quick setup test for html5/php/ajax/mysql combo (learning)

i've got my basic db with username and password as uni / uni
my html form
 
My form:

<form id="contactForm" action="doLogin.php" method="post">

  <h2>Login</h2>

  <ul>

    <li>
      <label for="userName">Your Username</label>
      <input type="text" name="userName" id="userName" placeholder="Enter Username" required="required" maxlength="40" />
    </li>
    <li>
      <label for="pWord">Your Password</label>
      <input type="password" id="pWord" placeholder="Enter Password" required="required" maxlength="40" />
    </li>

  </ul>

  <div id="formButtons">
    <input type="submit" id="submitForm" name="submitForm" value="Submit" />
    <input type="button" id="cancel" name="cancel" value="Cancel" />
  </div>

</form>

Open in new window

 
my doLogin.php

$unsafe_pw = $_POST['pWord'];
$safe_pw = mysql_real_escape_string($unsafe_pw);
$unsafe_un = $_POST['userName'];
$safe_un = mysql_real_escape_string($unsafe_un);

$sql="SELECT * FROM $tbl_name WHERE username='$safe_un' and password='$safe_pw'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

here's the problem, this always returns a count of 0 - however if i hardcode the password i.e.


$sql="SELECT * FROM $tbl_name WHERE username='$safe_un' and password='uni'";
then it's fine.
so the db connection is fine.
I can't see what the problem is.
if i do an echo $unsafe_pw - i'm getting nothing  - so that's failing somewhere in the post.
0
Comment
Question by:blue-genie
3 Comments
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 500 total points
ID: 37799851
Try replacing line no 15 to

<input type="password" name="pWord" id="pWord" placeholder="Enter Password" required="required" maxlength="40" />
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 37799912
Check out $_POST['userName'], unless there is no input tag with NAME 'userName', you get no such $_POST variable.

Bye, Olaf.
0
 
LVL 39

Author Closing Comment

by:blue-genie
ID: 37799929
aaargh. thanks sonawanekiran: - knew it was something silly that i was overlooking. thanks :-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now