php和html注册页面结果是空白页面

时间:2015-12-26 18:02:32

标签: php mysql

我试图为学校的项目创建一个网站。第一步应该是简单的 - 注册&登录页面。 PHP代码从来没有工作过...(有时由于代码中的问题而且大多数时候结果都是空白页。)

html代码:

<!doctype html>
<html>
<title>Tracycle Registration</title>
<link rel="stylesheet" href="test.css">
<div id="header">
<h1>Tracycle</h1>
</div>
<br>
<h3 align="center">Register with your email address</h3>
<br>
<form align="center" action="register.php" method="post">
<input type="email" id="textboxid" placeholder="Email" name="email" size="50" required>
<br><br>
<input type="password" id="textboxid" placeholder="Password" name="password" size="50" required>
<br><br>

<center><input type="submit" name="register" value="Register" ></center>
</form>
</html>

php代码:

<?php
$host = "127.0.0.1";
$user = "tracycle";                     
$pass = "";                                 
$db = "users";                          
$port = 3306;                               

$connection = mysqli_connect($host, $user, $pass, $db, $port)or die(mysql_error());

if(isset($_POST['submit']))
{
    $email = $_POST['email'];
    $password = $_POST['password'];

    $check_email = "SELECT * FROM users_information WHERE email='$email"; 

    $run = mysql_query($check_email);

    if(mysql_num_rows($run)>0)
    {
        echo "This email already exists!";
    }

    $query = "INSERT INTO users_information (email, password) VALUES ('$email', '$password')";
    if(mysql_query($query))
    {
        echo "Success!";
    }
}

?>

BTW我正在使用cloud9开发环境

您知道问题是什么以及为什么结果是空白页?(填写html表单并单击提交按钮后) 我很乐意得到帮助:)

2 个答案:

答案 0 :(得分:2)

if(isset($_POST['submit']))

必须

if(isset($_POST['register']))

尝试激活显示PHP错误: How do I get PHP errors to display?

答案 1 :(得分:2)

  

“php和html注册页面结果为空白页面”

空白页表示您遇到语法错误,代码中存在许多错误。

首先,if(isset($_POST['submit'])){...} 的条件语句永远不会发生,因为您的提交按钮具有register名称属性,而不是submit

将以下内容添加到您现有的代码中,并在结束?>代码之前,将回显Submit is not set.

else{
   echo "Submit is not set.";
   }

然后你在WHERE email='$email";中有一个缺少的引号会引发语法错误。

您正在使用mysqli_ API,但使用mysql_个功能。

来自不同MySQL API的不同功能不会混用。

你必须使用相同的连接,查询。

请参阅以下链接:

在检查错误时,会产生很多错误,其中一个是未定义的索引提交通知。

您目前的代码向SQL injection开放。使用mysqli_* with prepared statementsPDOprepared statements

<强>密码

我还注意到您可能以纯文本格式存储密码。不建议这样做。

使用以下其中一项:

其他链接:

HTML stickler。

您的HTML也包含无效标记。

应该有<head></head>个标记,其中包含样式表和标题声明,而且您的HTML包含在<body></body>标记中。

<!doctype html>
<html>
<head>
<title>Tracycle Registration</title>
<link rel="stylesheet" href="test.css">
</head>

<body>
<div id="header">
...
</form>

</body>
</html>