2015-06-22 56 views
0
if(isset($_POST["submit"])) 
    { 

    // Details for inserting into the database 

     $id = htmlentities($_POST["id"]); 
     $firstname = htmlspecialchars($_POST["firstname"]); 
     $lastname = htmlspecialchars($_POST["lastname"]); 
     $username = htmlspecialchars($_POST["username"]); 
     $password = htmlspecialchars($_POST["password"]); 

    // Dealing with inserting 

     $query = "INSERT INTO `myDatabaseForAll`.`users` (`id`, `firstname`, `lastname`, `username`, `password`) 
       VALUES (NULL, $firstname, $lastname,$username,$password)"; 
     $result = mysqli_query($connection,$query); 


     if(!$result) { 
      die('There were some errors '.mysqli_error($connection)); 
     } else { 
      redirect_to('index.php'); 
     } 

} 
+1

發送發送帖子的html表單的代碼 – Blip

+0

您可以添加您的表結構。那是mysql表創建語句? –

回答

0
$query = "INSERT INTO `myDatabaseForAll`.`users` (`id`, `firstname`, `lastname`, `username`, `password`) 
     VALUES (NULL, $firstname, $lastname,$username,$password)"; 

收到此錯誤?:未知列「姓」,你需要周圍的SQL文本精密組件單引號查詢上述查詢

變化

$query = "INSERT INTO `myDatabaseForAll`.`users` (`id`, `firstname`, `lastname`, `username`, `password`) 
     VALUES (NULL, '$firstname', '$lastname','$username','$password')"; 
+0

謝謝@habil shuklan –

0

由於表列名稱與您在查詢中給出的名稱不匹配,可能會發生此錯誤。如果不是這種情況,請嘗試下面的代碼。

$query = "INSERT INTO `myDatabaseForAll`.`users` (id, firstname, lastname, username, password) 
     VALUES (NULL, '".$firstname."', '".$lastname."','".$username."','".$password."')"; 

在您的查詢中,您使用php變量連接了一些字符串部分。所以這個連接應該使用連接運算符以上述方式完成。

相關問題