0 concat显示名字和姓氏,但只有名字保存到mysql数据库

时间:2016-05-01 10:01:48

标签: php

<?php
  $servername = "localhost";
  $username = "root";
  $password = "";
  $databasename = "test";

  $conn = new mysqli($servername , $username , $password, $databasename);
  $name = $_POST["firstname"];
  $last = $_POST["lastname"];
   $statement = mysqli_prepare($conn, "INSERT INTO user(firstname ,lastname) VALUES(?,?)");
   mysqli_stmt_bind_param($statement ,"si", $name,$last);
    mysqli_stmt_execute($statement);

    $response = array();
    $response["success"] = true;  

    echo json_encode($response);

?>

上面的php脚本中存在的问题是它在数据库中保存名字而无法保存姓氏。

1 个答案:

答案 0 :(得分:0)

问题在于这条线,

mysqli_stmt_bind_param($statement ,"si", $name,$last);
                                     ^ see here

应该是,

mysqli_stmt_bind_param($statement ,"ss", $name,$last);