2015-08-27 66 views
0

我找不到這是重試錯誤404的原因。我將此代碼放入表單元素的action屬性中。我真的對PHP很陌生,所以如果你發現有任何破壞腦的東西,那麼很抱歉。正在檢索錯誤404

<form method="post" action="<?php 
     $servername = ""; 
     $username = ""; 
     $password = ""; 
     $dbname = ""; 

     // Create connection 
     $con = mysqli_connect($servername, $username, $password, $dbname); 

     // Check connection 
     if (mysqli_connect_errno()) { 
     echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
     } 

     //Inputed in E-Mail Field 
     $Mail = $_POST['email']; 

     //Search for Mail 
     $sql = ("SELECT Mail FROM betakey WHERE Mail = '$Mail'"); 

     $result=mysqli_query($con,$sql); 
     mysqli_close($sql); 

     //If Mail is already registered 
     if (mysqli_num_rows($result) > 0) { 
      echo "This email is already registered. Wait for the Beta Key!"; 
      mysqli_close($con); 
      mysqli_free_result($result); 
     } 

     //Inserting Mail when its not registered  
?>"> 
    <input type="email" id="email" name="email" placeholder="Type your E-mail Address here" value="<?= isset($_POST['email']) ? htmlspecialchars($_POST['email']) : '' ?>"required="required"/> 
    <input name="submit" type="submit" value="Sign Up" id="SignUpButton"/> 
</form> 
+0

此代碼無法檢索404錯誤。向我們顯示調用此代碼的表單。 –

+0

添加了表單本身。 – KillZoneZ

+1

您的所有PHP代碼都是* not *在表單的操作中,是嗎?如果是,請將您的PHP代碼放在單獨的文件中,並將該文件名稱用作表單中的操作。 –

回答

0

您是否有(Mail)列或Mail列?我認爲問題是WHERE之後的(Mail)

$sql = ("SELECT Mail FROM betakey WHERE (Mail) = '$Mail'"); 

它應該是:

$sql = ("SELECT Mail FROM betakey WHERE Mail = '$Mail'"); 
+0

謝謝你這是不正確,但它不是什麼導致問題 – KillZoneZ

+0

是的,它會不顯示404錯誤。你可以在這裏閱讀更多http://php.net/manual/en/function.http-response-code.php – learner

2

你在內的所有形式的action屬性中你的PHP的,這是行不通的。從PHP分隔您的形式:

form.html

<form method="post" action="process.php"> 
<input type="email" id="email" name="email" placeholder="Type your E-mail Address here" value="" required="required" /> 
<input name="submit" type="submit" value="Sign Up" id="SignUpButton"/> 
</form> 

process.php(注意形式action="process.php"如何)

<?php 
    $servername = ""; 
    $username = ""; 
    $password = ""; 
    $dbname = ""; 
    // Create connection 
    $con = mysqli_connect($servername, $username, $password, $dbname); 

    // Check connection 
    if (mysqli_connect_errno()) { 
     echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 

    //Inputed in E-Mail Field 
    $Mail = $_POST['email']; 

    //Search for Mail 
    $sql = ("SELECT Mail FROM betakey WHERE Mail = '$Mail'"); 

    $result=mysqli_query($con,$sql); 
    mysqli_close($sql); 

    //If Mail is already registered 
    if (mysqli_num_rows($result) > 0) { 
     echo "This email is already registered. Wait for the Beta Key!"; 
     mysqli_close($con); 
     mysqli_free_result($result); 
    } 

    //Inserting Mail when its not registered  
?> 

你不應該有任何PHP代碼嵌入在HTML除非您希望PHP中的值包含在表單中。

此腳本將爲at risk for SQL Injection Attacks.瞭解有關preparedstatements,並考慮使用PDO,it's really not hard

另外,請不要爲你發出公開邀請鄉親破解您的數據發佈實際用戶名或密碼。

+0

我完全按照你告訴我的方式,它仍然給我404錯誤。 – KillZoneZ

+0

您的服務器設置爲運行PHP嗎?你*在服務器上做這件事,對吧?這意味着找不到文件(process.php)。它與HTML文件在同一個文件夾中嗎? –

+0

是,是,是:/ – KillZoneZ