這是我第一次嘗試SQL和PHP。我正在嘗試使用HTML,CSS,JavaScript,MySQL和PHP創建一個登錄頁面。麻煩與MySQL和PHP
<form method="POST" action="project-phpfile.php">
UserID <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="login" value="login">
</form>
PHP
文件:
<?php
$con=mysql_connect("localhost","root","kms010625") or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(project-database,$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 ENTERD WRONG ID AND PASSWORD... PLEASE RETRY...";
}
}
}
if(isset($_POST['submit']))
{
SignIn();
}
?>
的問題是,當我點擊登錄按鈕,只需PHP代碼出來,而不是其他。
請幫助。謝謝。
請確保您通過xampp或wamp運行腳本 – Ezhil
我看到您嘗試打開文件...您是否啓動了服務器? –
...如果您是PHP新手,最好使用MySQLi或Prepared Statements而不是'mysql_ *'函數(已棄用)。 – TribalChief