2016-12-05 95 views
3

我寫一個基本的PHP登錄/註冊腳本,出於某種原因,當我加入PHP命令未加載HTML加載。我看了一下源代碼,但沒有任何裝載。我希望我錯過了一些非常基本的東西,但是我也遇到了一些與Web服務器上安裝的PHP版本有關的問題。HTML沒有在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> 

我試圖打印POST請求,但這個didnt棚對這個問題的光

print_r($_POST); 
+0

是否使用類似的Apache2 web服務? – Troyer

回答

2

您正在使用過時的功能和您的if語句是不正確。

使用if(isset($_POST) && !empty($_POST)){

mysql_querymysqli_query,功能使用:

http://php.net/manual/en/function.mysql-query.php

mixed mysql_query (string $query [, resource $link_identifier = NULL ])

VS新一:

http://php.net/manual/en/mysqli.query.php

mixed mysqli_query (mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ])

你是第一個放置連接,並且比查詢,它不適合的mysql_query工作。在mysqli_query中,標記起作用。

+0

感謝Hespen, 我也在交換連接腳本中的mysql和msqli –

+0

您說你使用的是PHP 7.00,而mysql在這一點上,函數全部被mysqli取代!如果你正在運行一箇舊版本,你可能會得到它。請記住:在PHP中編寫代碼時,頁面爲空白。某處出現PHP錯誤。 – Hespen

0

使用本

if(isset($_POST['email']) && !empty($_POST['email'])){ 
+0

目前它託管在運行PHP 7.0的網絡註冊表服務器上。說這個我已經測試過5.3和5.6。在錯誤日誌中沒有錯誤,我測試了$ connection實際上建立了與MySQL的連接 –

0

檢查和下面的代碼審查,

<?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> 
+0

它在我的本地系統中工作。 –