<?php
session_Start();
if (isset($_POST['LOGIN']))
{
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mysite";
\t
\t
\t $conn = new mysqli($servername, $username, $password, $dbname);
\t
\t
\t if ($conn->connect_error)
\t
\t
{
die("Connection failed: ".$conn->connect_error);
}
\t else
{
\t $result1 = "SELECT userid, password FROM user WHERE username = '$username' And password = '$password'";
\t $queryResult = $conn->query($result1);
\t }
\t
\t if ($queryResult > 0)
\t {
\t
\t \t
\t \t
\t \t $_SESSION['username'] = $username;
\t \t header("location: home.php");
\t }
\t else
\t {
\t \t echo 'The username or password are incorrect!';
\t }
}
?>
<style>
.header{
width:100%;
background-color:#00adff;
float:left;
color:white;
padding: 1%;
}
.rightChuck{
float:right;
width:18%;
}
.menu{
float:left;
padding:5%;
}
#title
{
float:left;
margin-left:10px;
}
body{
margin:0px !important;
}
h1{
margin: 0px !important;
}
#main
{
text-align:left;
}
#content{
\t margin: auto;
position: absolute;
top: 100;
bottom: 100;
left: 100;
right: 100;
background: white;
\t border: 5px solid green;
width: 400px;
height: 200px;
\t
}
</style>
<html>
<head>
<title>Mysite.com</title>
</head>
<body>
<div class="header">
<div id="title">
<h1>Mysite.com</h1>
</div>
<div class="rightChuck">
<div class="menu">
<a href="login.php">LOGIN </a>
</div>
<div class="menu">
<a href="register.php">REGISTER</a>
</div>
</div>
</div>
<div style="float:left;width:100%;padding:left:10px;">
<h2>LOGIN</h2>
</div>
<div id="content">
<center>
<form name="form" method="post">
<table cellpadding="5" cellspacing="10">
<tr><th ><h3>USERNAME</h3></th><td><input type="text" placeholder="Username" name="username" size="20" id="textbox" required /></td></tr>
<tr><th><h3>PASSWORD</h3></th><td><input type="password" placeholder="Password" id="password"name="password" size="20" id="textbox" required /></td></tr>
</td>
</table>
<input type="submit" name="LOGIN" value="LOGIN" id="buttondesign" />
<br />
<br />
</form>
</div>
</body>
</html>
正常に動作していない、このログインページを設定する方法、正しい方法があり、私はdatabseからユーザー名とパスワードを確認するために、ログインボタンの[Go]をクリックしたときに、ユーザー名とパスワードが正しく、そのユーザー名とユーザーIDがセッションに格納されている場合は、ホームページに移動し、別のユーザー名とパスワードを間違って、そのエラーメッセージが表示されます。このコードには、ページは、ユーザー名とパスワードを確認しないで、セッションは格納されません。
<form name="form" method="post" action="login.php">
がある問題ににsession_startを解決する必要があり、これを修正(); not session_Start(); – Roy