我试图添加列ID将是一个主键与自动递增属性。所以我执行这个SQL查询:添加列ID到现有的表
ALTER TABLE `user_info` ADD `id` INT NULL AUTO_INCREMENT PRIMARY KEY FIRST ;
该列已成功创建,甚至为已存在的数据创建id。
但我无法在表格内插入任何东西。
<?php
require "init.php";
$name=$_POST["user"];
$user_email=$_POST["user_email"];
$user_pass=$_POST["user_pass"];
$sql_query="SELECT * FROM user_info WHERE user_email='$user_email'";
$check=mysqli_fetch_array(mysqli_query($con,$sql_query));
if(isset($check)){
\t $response["success"]=false;
\t $response["message"]="Email already exists";
\t echo json_encode($response);
}else{
\t $sql_query="insert into user_info values('$name','$user_email','$user_pass');";
if(mysqli_query($con,$sql_query)){
\t //echo "<h3> Data Insert success</h3>";
$response["success"]=true;
\t $response["message"]="Registration successful";
\t echo json_encode($response);
}
else{
\t $response["success"]=false;
\t $response["message"]="Registration unsuccessful";
\t echo json_encode($response);
}
}
?>
我用Google搜索了一圈,发现了,我可以在我的地方身份证插入0或空的。
我故意阅读:
为了利用该列的自动递增的能力优势,将排在该列不提供值。数据库将为您提供一个值。
代码运行良好,当我放弃列ID,但是当我添加它,我得到响应作为Registration unsuccessful
在我的JSON。
我在想什么?
我不知道我正在读取sql,但不应该为ID列允许NULL值。 – jeroen