?
Solved

PHP simple mysql login - can't find the problem

Posted on 2012-04-03
3
Medium Priority
?
248 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 2000 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 30

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

762 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