Solved

PHP simple mysql login - can't find the problem

Posted on 2012-04-03
3
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

717 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