Jump to content

[SOLVED] login php through MySQL reguirments ???


samoi

Recommended Posts

Hello guy, I know I should have re-phrase the subject  :P

I just done with the registration script, with cronix help :)

 

now, I need to create a simple.

and I tried to put it like this

 


<?php
$username = clean($_POST['username']);
$password = clean($_POST['password']);

$conn = mysql_connect("localhost","root","root");
$db = mysql_select_db("sam");

$checkuser = "SELECT * FROM users WHERE username = '$username'";
$checkuserlog = mysql_query($checkuser);
$checkpass = "SELECT * FROM users WHERE password = '$password'";
$checkpasslog = mysql_query($checkpass);

if($username != $checkuserlog )
{
echo 'wrong username';
}
elseif($checkpasslog != $password)
{
echo ' wrong pass';
}
else{
echo ' logged in! ';

}
function clean($str)
{return mysql_escape_string($str);}
?>

 

but it printed me wrone username !

 

I don't know why.

 

tell me the requirment to build this script!

Link to comment
Share on other sites


<?php
$username = clean($_POST['username']);
$password = clean($_POST['password']);

$conn = mysql_connect("localhost","root","root");
$db = mysql_select_db("sam");

$checkuser = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
$checkuserlog = mysql_query($checkuser);
$num_results = mysql_num_rows($checkuserlog);

if($num_results == 0)
{
echo 'wrong username or password';
}
else{
echo ' logged in! ';

}
function clean($str)
{return mysql_escape_string($str);}
?>

 

You can try this code.  It will not tell you which of username and password is wrong though.

 

There are 2 problems in your original code:

 

1.  You check username and password, but not username and password together.  If user A has password X and user B has password Y, then you can login with username A and password Y, even though they are not for the same user!

2.  You need to use mysql_fetch_row() after a query to get the actual data.

Link to comment
Share on other sites


<?php
$username = clean($_POST['username']);
$password = clean($_POST['password']);

$conn = mysql_connect("localhost","root","root");
$db = mysql_select_db("sam");

$checkuser = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
$checkuserlog = mysql_query($checkuser);
$num_results = mysql_num_rows($checkuserlog);

if($num_results == 0)
{
echo 'wrong username or password';
}
else{
echo ' logged in! ';

}
function clean($str)
{return mysql_escape_string($str);}
?>

 

You can try this code.  It will not tell you which of username and password is wrong though.

 

There are 2 problems in your original code:

 

1.  You check username and password, but not username and password together.  If user A has password X and user B has password Y, then you can login with username A and password Y, even though they are not for the same user!

2.  You need to use mysql_fetch_row() after a query to get the actual data.

 

Thank you man very much!

but what I really asked about, what are the requirments to build a login system script?

 

give me steps if you can please, and forgive my stupidity since I'm a beginner to the PHP, and I love so much, but I try my best to get it.

Link to comment
Share on other sites

I'm sorry guys,

But I mean, what if you want to build a login system script. what are you going to do first, second ....etc.

what are the required pages for that? example: login.php, logout.php, logincheck.php

 

that's what I mean, I want some guides to get me build a login script.

 

Note: I have allready build a registration script goes with Mysql database !

but I just want to know what proccess can i take to build this script!

 

Thank you guys

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.