我正在设置一个简单的登录页面,但是当我单击“提交”按钮时,浏览器会下载php文件,而不是使用php文件查询MySQL数据库。
我正在使用Jetbrains Webstorm进行此操作,而只是使用“运行”快捷方式来运行页面。
登录页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sign-In</title>
</head>
<body>
<div id="sign-in">
<fieldset style="width:30%"><legend>LOG-IN HERE</legend>
<form method="POST" action="scripts/connectivity.php">
Username<br><input type="text" name="user" size="40"><br>
Password<br><input type="password" name="pass" size="40"><br>
<input id="button" type="submit" name="submit" value="Log-In">
</form>
</fieldset>
</div>
</body>
</html>
connectivity.php
<?php
define('DB_HOST', 'REDACTED');
define('DB_NAME', 'REDACTED');
define('DB_USER', 'REDACTED');
define('DB_PASS', 'REDACTED');
$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error());
function SignIn() {
session_start();
if(!empty($_POST['user'])) {
$query = mysql_query("SELECT * FROM UserName WHERE userName = '$_POST[user]' AND pass = '$_POST[pass]'") or die(mysql_error());
$row = mysql_fetch_array($query) or die(mysql_error());
if(!empty($row['userName']) AND !empty($row['pass'])) {
$_SESSION['userName'] = $row['pass'];
echo "SUCCESSFULLY LOGIN TO USER PROFILE PAGE...";
} else {
echo "SORRY... YOU ENTERED WRONG ID AND PASSWORD... PLEASE RETRY...";
}
}
if(isset($_POST['submit'])) {
SignIn();
}
?>
我希望当我单击“提交”按钮时,它将告诉我该帐户是否为现有帐户。但是,单击“提交”后,我的浏览器会下载Connectivity.php文件
答案 0 :(得分:1)
我犯了一个愚蠢的错误,并将其另存为.html而不是.php,因此代码无法运行。