你能告诉我为什么我的代码不起作用吗?在我的用户名表中,我有两列,username
和<?php
require('dbConnect.php');
$Number = $_POST['phonenumber'];
// The ? below are parameter markers used for variable binding
// auto increment does not need prepared statements
$query = "INSERT INTO user (username) VALUES (?)";
$stmt = mysqli_prepare($con,$query) or die(mysqli_error($con));
//bind variables
mysqli_stmt_bind_param($stmt,"s",$u);
//$stmt->bind_param("s",$u);
mysqli_stmt_execute($stmt);
if(mysqli_query($con,$query))
{
echo 'Inserted correctly';
}
else
{
echo 'Error';
echo var_dump($stmt);
}
mysqli_stmt_close($stmt);
mysqli_close($con);
?>
。 user_id是自动增量所以我在我的Sql语句中没有这个,我认为这是正确的做法。
C:\wamp64\www\phpproject\php-project\insert.php:28:
object(mysqli_stmt)[2]
public 'affected_rows' => int -1
public 'insert_id' => int 0
public 'num_rows' => int 0
public 'param_count' => int 1
public 'field_count' => int 0
public 'errno' => int 1048
public 'error' => string 'Column 'username' cannot be null' (length=32)
public 'error_list' =>
array (size=1)
0 =>
array (size=3)
'errno' => int 1048
'sqlstate' => string '23000' (length=5)
'error' => string 'Column 'username' cannot be null' (length=32)
public 'sqlstate' => string '23000' (length=5)
public 'id' => int 1
我一直在&#39;错误&#39;,在我的var_dump中得到:
pip3
答案 0 :(得分:-2)
像这样使用null进行自动增量
$query = "INSERT INTO user (user_id,username) VALUES (null,$username)";