I have written php script for user login but instead of displaying the result the whole script is being displayed.I have given a .php file link as an action for the login form.
I am using xampp with php and mysql running do I need anything else?
the code is :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>Ch</title>
<meta name="description" content="education,India,College search in india,score evaluator" />
<meta name="author" content="RAJATEJAS" />
<meta name="viewport" content="width=device-width; initial-scale=1.0" />
<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<style type = "text/css">
user_login , input
{
display = inline;
}
</style>
</head>
<body>
<div>
<header>
<h1>Ch</h1>
</header>
<nav>
<p><a href="/">Home</a></p>
<p><a href="/contact">Contact</a></p>
</nav>
<div class = "user_login_form">
<form action = "chalo_login.php" method="post">
<label>Username:</label><input id = "username" type = "text" name = "username" autofocus placeholder="Enter Username"/><br />
<label>Password:</label><input id = "password" type = "password" name = "password" placeholder="Enter Password"/><br />
<input name = "submit" type = "submit" value = "Login" />
</form>
</div>
<footer>
<p>© Copyright by RAJATEJAS</p>
</footer>
</div>
</body>
</html>
<?php
session_start();
$_POST['username'];
$_POST['password'];
if ($username&&$password)
{
$connect = mysql_connect("localhost","root","");
mysql_select_db("phplogin") or die("could not find database");
$query = mysql_query(SELECT * FROM users WHERE username = "$username");
$numrow = mysql_num_rows($query);
if ($numrows !=0)
{
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row["username"];
$dbpassword = $row["password"];
}
if($username == $dbusername && $password == $dbpassword)
{
echo "You are logged in! ;
<a href ="member.php">Click here</a>";
$_SESSION["username"] = $dbusername;
}
else
{
echo "Incorrect password";
}
}else{die("Account does not exists");}
}
else
{
die ("Please enter details");
}
?>
You’ve got a few errors in your code, but I don’t know if they’re what are causing your problems.
Firstly in your CSS
user_loginshould be#user_loginto select elements with the ID “user_login”. Then,display = inline;should bedisplay: inline;.In your PHP…
…doesn’t do anything. I think you should have
And as Ethan mentioned in the comments above, your quotation marks are messed up:
…should probably be:
(Escape your quotation marks inside quotation marks using a backslash).
Fix those errors and see if it works then…
Also: as LeleDumbo says above, make sure the page is being loaded through Apache rather than opened as a file. The URL should begin with something like
127.0.0.1orlocalhost. If not, just put127.0.0.1into your address bar and browse to your file in the list that appears.Another error- your
SELECTstatement needs to be a string: