表字段将VARCHAR记录为0

时间:2019-04-16 01:17:59

标签: php mysql

我有一个包含6个字段的表格,分别是姓名,电子邮件,电话,性别,行业和教育。前四个字段记录了在mysql db中正确输入的值,行业和教育字段仅显示0。我到处查看并且找不到问题,感谢您的帮助。

表格: form

表结构: table structure

表值: table values

    <?php
$username = $_POST['username'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$gender = $_POST['gender'];
$industry = $_POST['industry'];
$education = $_POST['education'];

if (!empty($username) || !empty($email) || !empty($phone) || !empty($gender) || !empty($industry) || !empty($education)) {

    //create connection
    $conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
    if (mysqli_connect_error()) {
     die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error());
    } else {
     $SELECT = "SELECT email From register Where email = ? Limit 1";
     $INSERT = "INSERT Into register (username, email, phone, gender, industry, education) values(?, ?, ?, ?, ?, ?)";
     //Prepare statement
     $stmt = $conn->prepare($SELECT);
     $stmt->bind_param("s", $email);
     $stmt->execute();
     $stmt->bind_result($email);
     $stmt->store_result();
     $rnum = $stmt->num_rows;
     if ($rnum==0) {
      $stmt->close();
      $stmt = $conn->prepare($INSERT);
      $stmt->bind_param("ssssii", $username, $email, $phone, $gender, $industry, $education);
      $stmt->execute();
      echo "";
     } else {
      echo "Someone already register using this email";
     }
     $stmt->close();
     $conn->close();
    }
} else {
 echo "All field are required";
 die();
}
?>

1 个答案:

答案 0 :(得分:0)

语法: bind_param(字符串$ types,混合&$ var1 [,混合&$ ...])

$ types 一个包含一个或多个字符的字符串,这些字符指定相应绑定变量的类型:

类型说明字符

i 对应的变量具有整数类型

d 对应变量的类型为double

s 对应变量的类型为字符串

b 对应的变量是一个blob,将以数据包的形式发送

在您的情况下,所有内容都是字符串,因此请使用“ ssssss”而不是“ ssssii”

  $stmt->bind_param("ssssss", $username1, $email, $phone, $gender, $industry, $education);