Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP Login form problem, need help
Old 01-24-2012, 05:23 AM PHP Login form problem, need help
Experienced Talker

Posts: 39
Name: Farris
Trades: 0
Hi,

Code:
<?php

require "connection.php";

$run = mysql_query($query);

$username = $_POST['username'];
$password = $_POST['password'];

$query = "SELECT 'ID' FROM '****' WHERE 'username' = '$username' AND 'password' = '$password' LIMIT 1";
$request = mysql_query($query);
$run = mysql_num_rows($request);

if($run==1){
		mysql_fetch_array($query);
		}
		else{
			echo "Not Correctos";
			}

?>


<form id="form1" name="form" method="post" action="login.php">
  <table border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Username:</td>
      <td><label for="textfield"></label>
      <input type="text" name="username" id="textfield" /></td>
    </tr>
    <tr>
      <td>Password:</td>
      <td><label for="textfield2"></label>
      <input type="text" name="password" id="textfield2" /></td>
    </tr>
  </table>
  <p>
    <input type="submit" name="button" id="button" value="Login" />
  </p>
</form>
Whats wrong with this PHP code it doesn't work. I would like to login but I can't is there anything wrong

FarrisFahad
FarrisFahad is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-24-2012, 07:03 AM Re: PHP Login form problem, need help
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
The first two aren't things causing your script to fail, but they definitely need addressing:

1. You are wide open for a SQL injection. Taking raw user input and putting it into a query is a bad idea, especially in a login script.

2. This is not how you store a user's password. If you are going to ask users to give you private information, you should take steps to ensure it is properly secured. Passwords should be stored as hashes, never as the raw string. See the following: http://www.itnewb.com/tutorial/Encry...BKDF2-Standard

3. You are using single quotes in place of backticks in your query. Single quotes are used to enclose literal strings, backticks are used with table and column names. In most cases you don't need to use backticks at all. Removed the quotes from 'ID', '****', 'username', and 'password'. Right now you are asking the DB if $username is the literal 'username'.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 01-24-2012 at 07:06 AM..
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-24-2012, 08:25 AM Re: PHP Login form problem, need help
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Also, mysql_fetch_array() should be given the result as parameter (in your case, the $request variable), not the query string.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 01-24-2012, 08:35 AM Re: PHP Login form problem, need help
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Also, there is no reason why a script being written now should use the mysql_* functions. Use mysqli or PDO. Using prepared statements will fix your SQL injection problem.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-26-2012, 12:58 AM Re: PHP Login form problem, need help
Experienced Talker

Posts: 39
Name: Farris
Trades: 0
Thank you guys so much you have really helped me
In that code I was only trying to successfully login the user and I did thanks to you guys
thanks NullPointer
thanks lizciz
FarrisFahad is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP Login form problem, need help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15981 seconds with 12 queries