Jump to content

Recommended Posts

I was woking on these two codes belwo, when I try to enter the username and the password. It just shows me the same page again.

 

<?php

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

setcookie("username","$username",time()+86400);

if($login=='yes'){
$con = mysql_connect("localhost","root","");

mysql_select_db("login");

$get = mysql_query("SELECT count(id) FROM login WHERE user='$username'
and pass='$password'");

$result = mysql_result($get, 0);

if($resut!=1){
echo "Invalid login";
}
else {
echo "Login Successful, Welcome back".$_COOKIE['username']."sir/madam";
$_SESSION['username']=$username;
}
}

 

 

 

<html>
<body>

<form action"login1.php?login=yes" method="POST">
Username:<input type="text" name="username" />
<br/>
<br/>
Password:<input type="password" name ="password"/>
<br />
<input type="submit" value="Submit" />

</form>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/
Share on other sites

Yes, I did

 

<html>
<body>

<form action="login.php" method="POST">
Username:<input type="text" name="username" />
<br/>
<br/>
Password:<input type="password" name ="password"/>
<br />
<input type="submit" value="Submit" />

</form>

</body>
</html>

 

Why are you checking if login == 1 on login.php? There's no need for that. Take that out.

Link to comment
https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/#findComment-1023832
Share on other sites

Do you mean login ==yes..

 

well, I have taken that out.. It keeps telling me Invalid login

 

<html>
<body>

<form action="login.php" method="POST">
Username:<input type="text" name="username" />
<br/>
<br/>
Password:<input type="password" name ="password"/>
<br />
<input type="submit" value="Submit" />

</form>

</body>
</html>

 

 

<?php

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

setcookie("username","$username",time()+86400);


$con = mysql_connect("localhost","root","");

mysql_select_db("login");

$get = mysql_query("SELECT count(id) FROM login WHERE user='$username'
and pass='$password'");

$result = mysql_result($get, 0);

if($resut!=1){
echo "Invalid login";
}
else {
echo "Login Successful, Welcome back".$_COOKIE['username']."sir/madam";
$_SESSION['username']=$username;
}



?>

 

 

these are my updated codes

Link to comment
https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/#findComment-1023844
Share on other sites

You need to slow down when you are writing your code. You keep making spelling errors and other such things. In your if statement $result is spelled wrong. You left out the lowercase "L". Also there is no need to do if($result!=1)

You should be able to just do if(!$result)

Link to comment
https://forums.phpfreaks.com/topic/194676-log-in-with-mysql/#findComment-1023851
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.