我对PHP和MySQL很陌生。我面临一个问题:一些记录被插入到数据库中,而有些记录没有被插入。有两张桌子
登录表没有问题,它总是插入记录。但是配置文件表有一个问题。有些记录已经插入,但有些没有。
我的数据库正在直播。很多人填写表格,所以我没有看到第二张表的记录。这是代码:
$pwd= $_POST['spwd'];(Get all values in the form of post)
$a1 = mysql_query("INSERT INTO Login (email,password,active) VALUES('$email','$pwd','1')");
$fk=mysql_insert_id();
if($fk!=0)
{
$a2 = mysql_query("INSERT INTO Profile (name,father,age,gender,kids,nationality,house,height,whenmarry,description,partnerquality,imagepath,email,mobile,mstatus,cast,education,religion,aqeeda,peer,madaniwork,country,city,zip,job,familydetail,salary,bodybuilt,fklogin)
VALUES('$name','$father',$age,$gender,$kids,'$nationality','$house','$height',$whenmarry,'$description','$partnerquality','$new_image_name','$email','$mobile',$ms,'$mothertongue','$education',$religion,$aqeeda,'$peer',$mwork,$country,'$city','$zip','$sjob','$fd','$salary',$bbuilt,$fk)");
}
if ($a1 and $a2) {
$response["success"] = 1;
$response["message"] = "Register Successfully";
echo json_encode($response);
}发布于 2014-11-24 06:20:35
我发现了我的错误--没有“主键”或“唯一”约束的问题,但我忘了在数据库字段中添加,而第二个问题是用户给出了输入5'6,这会使问题插入到数据库中,所以我使用mysql_real_escape_string来解决我的问题。
发布于 2014-11-10 07:06:54
确保配置文件表中没有“主键”或“唯一”约束,因为如果存在“主键”或“唯一”约束,则不允许插入重复的值。还请确保变量对于不允许在MySQL中插入空值的列具有某些值。(在MySQL中,默认情况下不允许NULL )
https://stackoverflow.com/questions/26838324
复制相似问题