我正在使用mysql_query来执行插入查询。由于DB无法插入Educations列的值,因此无法保存特定用户的数据,返回false结果。这对剩下的用户来说很好。
$result = mysql_query("INSERT INTO user (FirstName,LastName,Pic,Birthday,Industry,Languages,Summary,Email,Positions,Skills,Publications,Volunteer,Location,Awards,Certifications,Interests,Educations)
values ('$first_name','$last_name','$pic','$birthday','$industry','$languages','$summary','$email','$positions','$skills','$publications','$volunteer','$location','$awards','$certifications','$interests','$education')",$mysql);
所有字段都是字符串值。
答案 0 :(得分:1)
该变量可能无法转义。我建议您切换到使用PDO库,因为从PHP 5.5开始,将不推荐使用MySQL原生扩展。与MySQL本机相比,PDO具有许多优点,例如预处理语句和命名参数。准备方法将转义并自动引用您传入的变量。您不必再担心它了。看看我对你当前代码的重写:
$pdo = new PDO($dsn, $user, $password);
$values_array = array(
':first_name' => $first_name,
':last_name' => $last_name,
':pic' => $pic,
':birthday' => $birthday,
':industry' => $industry,
':languages' => $languages,
':summary' => $summary,
':email' => $email,
':positions' => $positions,
':skills' => $skills,
':publications' => $publications,
':volunteer' => $volunteer,
':location' => $location,
':awards' => $awards,
':certifications' => $certifications,
':interests' => $interests,
':education' => $education
);
$result = $pdo->prepare('INSERT INTO user (FirstName,LastName,Pic,Birthday,Industry,Languages,Summary,Email,Positions,Skills,Publications,Volunteer,Location,Awards,Certifications,Interests,Educations) values (:first_name,:last_name,:pic,:birthday,:industry,:languages,:summary,:email,:positions,:skills,:publications,:volunteer,:location,:awards,:certifications,:interests,:education)');
$result->execute($values_array);
您可能需要考虑切换到PDO以供将来证明。
答案 1 :(得分:0)
我注意到大多数值变量都是复数,除了$ education之外,尽管关键是复数。
除此之外,请查看转义和您的报价。