Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP simple mysql login - can't find the problem

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

636 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