0

I am new in php and I have created a php login page where it will retrive data from a table and check a print "login successful" or "login failed". Now after execution of the codeI am giving correct data but all the time it is replying "login failed" plese help me

<?php

$hostname = 'localhost';
$dbname = 'phplog';
$username = 'root';
$password = '';

mysql_connect($hostname, $username, $password);
mysql_select_db($dbname);

$use = $_POST['data'];
$use = stripslashes($use);
$use = mysql_real_escape_string($use);
$get = "SELECT * FROM user WHERE username='$use'";
$set = mysql_query($get);
$row = mysql_num_rows($set);
if($row == 1){
print("login successful");
}
else{
print("Login failed");
}

?>
5
Contributors
23
Replies
24
Views
5 Years
Discussion Span
Last Post by subhadeep.majumdar.733
0

14.
$get = "SELECT * FROM user WHERE username='$use'";
15.$set = mysql_query($get);
16.$row = mysql_num_rows($set);
17.if($row == 1)

Store it in a $_SESSION, otherwise I don't think it's being fired.

if(mysql_num_rows($result)==0)
{
echo "ERROR - No mactching rows from the database!<br/>";
}
else
{   
$_SESSION['ADMIN'] = $_POST["admin"];
}

Then you will be able to use it globally just by adding session_start(); at the beginning of the page.

Edited by SQLpower

0

Hello,pls check the username field in the table must be unique
and in the condition may intiate $row=0; and use "$row >= 1" instead of "$row == 1",
it should worked:

<?php
$hostname = 'localhost';
$dbname = 'phplog';
$username = 'root';
$password = '';
mysql_connect($hostname, $username, $password);
mysql_select_db($dbname);
$use = $_POST['data'];
$use = stripslashes($use);
$use = mysql_real_escape_string($use);
$get = "SELECT * FROM user WHERE username='$use'";
$set = mysql_query($get);
$row=0;
$row = mysql_num_rows($set);
if($row >= 1){
print("login successful");
}
else{
print("Login failed");
}
?>

.
%%^Murtada^%%

0

If you have a question, post a thread, containing both your ideas and code , otherwise there isn't any point stealing someon else's thread.

Edited by SQLpower

0
<?php
$submit = @$_POST['submit'];
//form data
$fullname = strip_tags (@$_POST['fullname']);
$username = strip_tags (@$_POST['username']);
$password= strip_tags(@$_POST['password']);
$repeatpassword = strip_tags(@$_POST['repeatpassword']);
$date =date("Y-m-d");
if ($submit)
{
// check for existance
if($fullname&&$username&&$password&&$repeatpassword)
{

if($password==$repeatpassword)
{

//chechk char length of username and fullname
if (strlen($username)>25||strlen ($fullname)>25)
{
echo ("Length of username or fullname is too long!");
}
else
{
//check password length
if(strlen($password)>25||strlen ($password)<6)
{
 die ("Password must be  between 6 and 25 characters");
}
else
{
//register the user!

//encrypt password
$password = md5($password);
$repeatpassword = md5($repeatpassword);
// open database
$connect = mysql_connect("localhost","root","");
mysql_select_db("phplogin");  // select database

$queryreg =mysql_query("
INSERT INTO users VALUES ('','$fullname','$username','$password','$date',)
");
die ("You have been registered!<a href='index.php'> Return to Login page</a>");

}


}

}
else
 die ("Your password do nat match!");
}
else
 die("Please fill in <b>all</b> fields!");


}
?>
0

<body>
<form action="login.php" method="post">
Username: <input type='text' name ='username'><br>
Password: <input type="password" name='password'><br>
<input type="submit" value="Log in">
</form>

</body>

0

i wont to make REGISTER as link in the second table,so it can send me in register page,can you help me

0

Hello andyy121,I think this code above it's for sign up not login.but it can be usefull

0

i wont to connec this two pages.example: when i click Register in the html pages it can lead me in Register in php pages how i can do that

0

check this code:

<form action="" method="post" >
name:<input name="fullname" size="25">
username:<input name="username" size="25">
password:<input type="password" name="password" size="25">
repeatpassword:<input type="password"  name="repeatpassword" size="25">
<input type="submit" name="submit" value="Register">

</form>

<?php
if(isset($_POST['submit']))
{
//form data
$fullname = strip_tags (@$_POST['fullname']);
$username = strip_tags (@$_POST['username']);
$password= strip_tags(@$_POST['password']);
$repeatpassword = strip_tags(@$_POST['repeatpassword']);
$date =date("Y-m-d");
if ($submit)
{
// check for existance
if($fullname&&$username&&$password&&$repeatpassword)
{
if($password==$repeatpassword)
{
//chechk char length of username and fullname
if (strlen($username)>25||strlen ($fullname)>25)
{
echo ("Length of username or fullname is too long!");
}
else
{
//check password length
if(strlen($password)>25||strlen ($password)<6)
{
die ("Password must be between 6 and 25 characters");
}
else
{
//register the user!
//encrypt password
$password = md5($password);
//$repeatpassword = md5($repeatpassword);
// open database
$connect = mysql_connect("localhost","root","");
mysql_select_db("phplogin"); // select database
$queryreg =mysql_query("INSERT INTO users VALUES ('','$fullname','$username','$password','$date')") ;
//++++++++++new lines++++++++++++++++++++++++
if($queryreg)
{
echo "<script>alert('".$alrt13."');</script>";    
echo "<meta http-equiv='refresh' content='0; url=index.php' >";//too login page 
}
}
}
}
else
die ("Your password do nat match!");
}
else
die("Please fill in <b>all</bfields!");
}
}
?>
0

I added this conditon to check if submition is done:

if(isset($_POST['submit']))

0

if same error happands again, pls test the connection then test your sql statement,pls give the structure of user table ,to help you.

0

listen forget all this i just wont to make the REGISTER in link whcih it is ia the html page and it can lead me to register page

0

okey it's easy:
this link in the home page okay:

<a href="register.php" >Registeration</a>

do you mean that!!

the code of html , and php they can be in one page 'register.php'

0

It the the field name and the value in that field of the table user in the above code which I need help. Pls someone try to execute the above code in your computer and tell me wheather you are getting same error or not.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.