Solved

PHP simple mysql login - can't find the problem

Posted on 2012-04-03
3
243 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.  …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

785 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