[英]HTML not being loaded in PHP Document
I am writing a basic PHP login/Registration script and for some reason as soon as I add a PHP command the HTML isn't loaded. 我正在编写一个基本的PHP登录/注册脚本,出于某种原因,只要我添加PHP命令,就不会加载HTML。 I had a look at the source but there is nothing loaded at all. 我查看了源代码,但根本没有任何内容。 I am hoping I have missed something very basic, but I am also having a couple of teething issues with the version of PHP installed on the web server. 我希望我错过了一些非常基本的东西,但我对Web服务器上安装的PHP版本也有一些问题。
<?php
require_once('connect.php');
if(isset($_POST) & !empty($_POST)){
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
$password =md5($_POST['password']);
$sql = "INSERT INTO 'login' (username, email, password) VALUES ('$username, $email, $password)";
$result = mysql_query($connection, $sql);
if($result){
echo "User Rego Secusseflllgk";
}else{
echo "User rego faile";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>USer Reg in PHP & MySQL</title>
</head>
<center>
<body>
<div class="container">
<form class="form-signin" method="POST">
<h2 class="form-sigin-heading">Please register</h2>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">@</span>
<input type="test" name="username" class="form-control" placeholder="Username" required>
</div>
<label for="inputEmail" class="sr-only">Password</label>
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Register</button>
<a class="btn btn-lg btn-primary btn-block" href="login.php">Login</a>
</form>
</div>
</body>
</html>
I tried to print the POST request but this didnt shed any light on the issue 我试图打印POST请求,但这并没有解决这个问题
print_r($_POST);
You are using deprecated functions and your if-statement is incorrect. 您正在使用已弃用的函数,并且您的if语句不正确。
Use if(isset($_POST) && !empty($_POST)){
使用if(isset($_POST) && !empty($_POST)){
The mysql_query
should be mysqli_query
, the function you use: mysql_query
应该是mysqli_query
,你使用的函数:
http://php.net/manual/en/function.mysql-query.php http://php.net/manual/en/function.mysql-query.php
mixed mysql_query ( string $query [, resource $link_identifier = NULL ] )
VS the new one: VS新的:
http://php.net/manual/en/mysqli.query.php http://php.net/manual/en/mysqli.query.php
mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )
You are placing the connection first, and than the Query, which doesn't work for mysql_query. 您首先放置连接,而不是查询,这对mysql_query不起作用。 In mysqli_query that mark-up does work. 在mysqli_query中,标记确实有效。
用这个
if(isset($_POST['email']) && !empty($_POST['email'])){
Check and review below code, 检查并查看以下代码,
<?php
require_once('connect.php');
if(isset($_POST) & !empty($_POST)){
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
$password =md5($_POST['password']);
$sql = "INSERT INTO login (username, email, password) VALUES ('".$username."', '".$email."', '".$password."')";
$result = mysql_query($sql);
if($result){
echo "User Rego Secusseflllgk";
}else{
echo "User rego faile";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>USer Reg in PHP & MySQL</title>
</head>
<center>
<body>
<div class="container">
<form class="form-signin" method="POST">
<h2 class="form-sigin-heading">Please register</h2>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">@</span>
<input type="test" name="username" class="form-control" placeholder="Username" required>
</div>
<label for="inputEmail" class="sr-only">Email</label>
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Register</button>
<a class="btn btn-lg btn-primary btn-block" href="login.php">Login</a>
</form>
</div>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.