MySQL和PHP的麻烦

时间:2014-07-07 10:18:14

标签: php html mysql

这是我第一次尝试SQL和PHP。我正在尝试使用HTML,CSS,JavaScript,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代码,而不是其他内容。 enter image description here

请帮忙。谢谢。

3 个答案:

答案 0 :(得分:3)

PHP在服务器上运行。

如果要在本地运行PHP脚本,则必须安装本地Web服务器。在Windows上,最快速,最简单的方法是使用XAMPPWAMPServer或类似的包含PHP,Apache和MySQL的包。

答案 1 :(得分:2)

Try these steps:
1:- Download xampp URL: https://www.apachefriends.org/download.html
2:- Install xampp in your system.
3:- Create new directory in xammp/htdocs/webpages
4:- Create new file in xammp/htdocs/webpages/project-phpfile.php
5:- Open local server URL: http://localhost/webpages/project-phpfile.php

答案 2 :(得分:1)

正如我在你发布的图片中看到的那样。你没有使用Xampp。 PHP在Xampp上运行。首先 Install 。然后将所有代码数据粘贴到 C:\ Xampp \ htdocs 中。然后打开浏览器。运行 localhost / projectFolder