主要的PHP问题

use*_*180 0 php sql database login

我正在尝试创建一个简单的登录系统.当我运行登录表单(使用正确的用户名和密码)时,似乎没有运行php.有什么建议?

<?php
$host="linuxserver"; // Host name
$username="jparry2"; // Mysql username
$password=""; // Mysql password
$db_name="jparry2"; // Database name
$tbl_name="customer"; // Table name

// Connect to server and select databse.
mysqli_connect("$host", "$username", "$password")or die("cannot connect");
mysqli_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysqli_query($sql);

// Mysql_num_row is counting table row
$count=mysqli_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file “login_success.php”
session_register("myusername");
session_register("mypassword"); 
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

<html>
<body>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

编辑添加的登录表单代码

<html>
<head><title>Login</title></head>
<body>


<form action='checklogin.php'
                method='POST' style='margin: .5in'>
    <p><label for='user_name' style='font-weight: bold;
          padding-bottom: 1em'>USER ID: </label>
       <input type='text' name='myusername' id='myusername'
          value='' /></p>
    <p><label for='password' style= 'font-weight: bold'>Password: </label>
       <input type='password' name='mypassword' id='mypassword'
          value='' /></p>
    <p><input type='submit' value='Login'> </p>
       <input type='hidden' name='sent' value='yes'/>

<a href= "/home/jparry2/public_html/register.php">Register</a>

    </form>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Mik*_*e B 5

如果您的浏览器要求您下载php文件,则意味着没有调用php解释器.即你没有正确安装或配置它.