2014-09-10 57 views
-2

在此輸入表單中。輸入不會被正確地轉移到sql數據庫中。 sqlAddUser.php = pastebin.com/W9BH0D3s 形式爲:表單不會將數據傳遞到SQL輸入

<form action="sqlAddUser.php" method="post"> 
<div class="row"> 
<div class="large-12 columns"> 
<label>Username: 
    <input type="text" placeholder="Insert Username here!" name="user"/> 
    </label> 
</div> 
</div> 
<div class="row"> 
<div class="large-12 columns"> 
    <label>Password: 
    <input type="password" placeholder="Insert Password Here!" name="password" /> 
    </label> 
    </div> 
</div> 
<div class="row"> 
<div class="large-12 columns"> 
    <label>Email: 
    <input type="text" placeholder="[email protected]" name="email" /> 
    </label> 
</div> 
</div> 
<div class="row"> 
<div class="large-12 columns"> 
    <label>First Name: 
    <input type="text" placeholder="Ben" name="firstName" /> 
    </label> 
</div> 
</div> 
<div class="row"> 
<div class="large-12 columns"> 
    <label>Surname Name: 
    <input type="text" placeholder="Brown" name="surname" /> 
    </label> 
</div> 
</div> 
<input type="submit"> 
</form> 

然後,這時候通過我的INSERT INTO腳本運行甫一沒有被添加到數據庫中。

+2

過得好變量?從sqlAddUser.php顯示你的代碼 – 2014-09-10 22:30:18

+0

如果你在sqlAddUser.php上var_dump($ _ POST),你看到了什麼? – Ferox 2014-09-10 22:31:02

+0

http://pastebin.com/W9BH0D3s是代碼。和var_dump給出了數組(0){} – 2014-09-10 22:34:33

回答

1

您使用name="user"$_POST['username']改變它$_POST['name']
或更改name="user"name="username" - 他們需要匹配。


<input type="text" placeholder="Insert Username here!" name="user"/> 
                  ^^^^ 

$username = mysqli_real_escape_string($con, $_POST['username']); 
                ^^^^^^^^ 

按你的引擎收錄文件http://pastebin.com/W9BH0D3syour commment

<?php 

       // Create connection 
     $con=mysqli_connect("*****", "******", "*****", "*****"); 

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

    $username = mysqli_real_escape_string($con, $_POST['username']); 
    $password = mysqli_real_escape_string($con, $_POST['password']); 
    $email = mysqli_real_escape_string($con, $_POST['email']); 
    $firstName = mysqli_real_escape_string($con, $_POST['firstName']); 
    $surname = mysqli_real_escape_string($con, $_POST['surname']); 

    mysqli_query($con,"INSERT INTO users (username, password, email, firstName, surname) 
    VALUES ('$username', '$password', '$email', '$firstName', '$surname')");  
?> 

編輯:

if(isset($_POST['submit'])){ 
    $con=mysqli_connect("xxx", "xxx", "xxx", "xxx"); 

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

if(isset($_POST['username'])){ $username = mysqli_real_escape_string($con, $_POST['username']); } 
if(isset($_POST['password'])){ $password = mysqli_real_escape_string($con, $_POST['password']); } 
if(isset($_POST['email'])){ $email = mysqli_real_escape_string($con, $_POST['email']); } 
if(isset($_POST['firstName'])){ $firstName = mysqli_real_escape_string($con, $_POST['firstName']); } 
if(isset($_POST['surname'])){ $surname = mysqli_real_escape_string($con, $_POST['surname']); } 

$sql="INSERT INTO users (username, password, email, firstName, surname) VALUES ('$username', '$password', '$email', '$firstName', '$surname')"; 
if (!mysqli_query($con,$sql)){ 
    die('Error:' . mysqli_error($con)); 
} 
var_dump($_POST); 
echo "1 record added"; 
}