Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
(database= newweb
table= loginform
user01 = janaka
pass01= janaka)

What I have tried:

<pre><?php

$host = "localhost";
$user = "root";
$Password = "";
$db = "newweb";

mysql_connect($host, $user, $Password);
mysql_select_db($db);

if (isset($_post['UserName'])) 
{
	$Uname = $_post['UserName'];
	$Password = $_post['Password'];

	$sql = "select * from loginform where User01='".$Uname."' AND Pass01='".$Password."' limit 1";

	$result=mysql_query($sql);

	if(mysql_num_rows($result)==1)
	{
		echo "You have sucessfully logged in";
		exit();
		}
			else
			{
				echo "You have entered incorrect Password";
				exit();
}
}
?>
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<link rel="stylesheet" type="text/css" href="logingform.css">
	<link rel="stylesheet" type="text/css" href="l.css">
</head>
<body>
	<div class="logingbox">
		<img src="user.png" class="avatar">
		<h1>Loging Here</h1>
			<form method="post" action="#">
				<p>User name</p>
				<input type="text" name="User Name" placeholder="Enter UserName">
				<p>Password</p>
				<input type="Password" name="Password" placeholder="Enter Password"><br>
				<input type="submit" name="submit" value="Login"><br>
				<a href="a">Forget Password</a><br><br>
				<p class="not-an-account">If you don't have a account</p>
				                      <a href="b">Sign Up</a>
			</form>
	</div>
</body>
</html>
Posted
Updated 13-Dec-19 20:47pm
Comments
Richard MacCutchan 14-Dec-19 5:50am    
Please, please, do NOT store your passwords in clear text.

PHP
$sql = "select * from loginform where User01='".$Uname."' AND Pass01='".$Password."' limit 1";

Not necessary a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
 
Share this answer
 
To add to what PatriceT says:
1) Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
SQL
DROP TABLE MyTable;
A perfectly valid "delete the table" command
SQL
--'
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?

2) Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^] - the code is in C#, but PHP has methods to do it for you: password_hash() – used to hash the password, and password_verify() – used to verify a password against its hash.
And remember: if this is web based and you have any European Union users then GDPR applies and that means you need to handle passwords as sensitive data and store them in a safe and secure manner. Text is neither of those and the fines can be .... um ... outstanding. In December 2018 a German company received a relatively low fine of €20,000 for just that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900