我在本地经营一个网站。我已经为登录表单创建了一个php脚本。
<?php
#starts a new session
session_start();
#includes a database connection
$serverName = "SQLServerNamehere"; //serverName\instanceName
$connectionInfo = array( "Database"=>"DatabaseNameHere",
"UID"=>"ServerUsernameHere", "PWD"=>"ServerPasswordHere");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
#catches user/password submitted by html form
$email = $_POST['email'];
$password = $_POST['password'];
#checks if the html form is filled
if(empty($_POST['email']) || empty($_POST['password'])){
echo "Fill all the fields!";
}else{
#searches for email and password in the database
$query = "SELECT * FROM [dbo].[Test] WHERE UserEmail(SQL Table
column)='{$email}' AND UserPassword(SQL table column)='{$password}'";
$result = sqlsrv_query($conn, $query);
#checks if the search was made
if($result === false){
die( print_r( sqlsrv_errors(), true));
}
#checks if the search brought some row and if it is one only row
if(sqlsrv_has_rows($result) != 1){
echo "Email/password not found";
}else{
#creates sessions
while($row = sqlsrv_fetch_array($result)){
$_SESSION['id'] = $row['id'];
$_SESSION['name'] = $row['name'];
$_SESSION['user'] = $row['user'];
$_SESSION['level'] = $row['level'];
}
#redirects user
header("Location: homepage.html");
}
}
?>
此文件名为signin.php
我的html登录表单名为signin.html:
<form class="login-form" action = 'signin.php' method="post">
<input type="text" placeholder="email"/>
<input type="password" placeholder="password"/>
<button>login</button>
</p> -->
</form>
现在,当用户在输入正确的凭据后单击login按钮时,我希望用户被重定向到homepage选项卡,但是当您输入凭据并单击login按钮时,它只显示PHP代码。我是新来的,有人能给我解释一下我怎样才能让这个工作吗?谢谢