好吧,我似乎发现了这个问题。
因为通过获取HTML表单字段的子字符串自动生成的字段的值,其中一个值显示为 id (它可以是在回声中看到我发布了吼叫)。看起来更新,并没有失败,但产生了这种意外行为。
感谢所有为这个愚蠢的问题提供帮助和抱歉的人。
执行像
之类的更新语句后UPDATE tablename SET field='value' WHERE field='value'
没有触及我的主键,它会将之前的值从0变为0.
有什么想法吗?
MySQL服务器版本:5.5.37-0 + wheezy1
这是生成查询的代码
$query2 = "UPDATE student SET ";
foreach ($_POST as $the_key => $a_post_arg) {
if (strcmp($the_key, "student_password") === 0) {
//without activation
$a_post_arg = md5($a_post_arg);
//with activation
//$a_post_arg = "Not activated!";
}
if (strcmp($the_key, "student_registration_year") === 0)
$a_post_arg = $a_post_arg . "-00-00";
if (strcmp(substr($the_key, 0, 14), "student_stats_") === 0 || strcmp($the_key, "student_validationImageTextfield") === 0) {
$student_stats[$the_key] = $a_post_arg;
continue;
}
if (strcmp(substr($the_key, 0, 7), "student") === 0 && strcmp($the_key, "student_email_retype") !== 0 && strcmp($the_key, "student_password_retype") !== 0) {
if (strcmp($the_key, "student_email") !== 0) {
if (strcmp($the_key, "student_select_dept") === 0) {
$query2 .= "dept='" . addslashes($a_post_arg) . "', ";
} else if (strcmp($the_key, "student_semester") === 0) {
$query2 .= "studying_semester='" . addslashes($a_post_arg) . "', ";
} else if (strcmp($the_key, "student_father_name") === 0) {
$query2 .= "fathers_name='" . addslashes($a_post_arg) . "', ";
} else if (strcmp($the_key, "student_academic_id") === 0) {
$query2 .= "academicIDNumber='" . addslashes($a_post_arg) . "', ";
} else {
$query2 .= substr($the_key, 8) . "='" . addslashes($a_post_arg) . "', ";
}
}
}
}
$query2 .= "status='registered' WHERE email='" . $_POST['student_email'] . "';";
这是$ query2的回显。表格的PK是自动增量字段 ID 和电子邮件字段。
query 2 = UPDATE student SET name='Όνομα', surname='Επώνυμο', dob='1970-09-09',
fathers_name='Ονοματεπώνυμο πατέρα', mother_name='Ονοματεπώνυμο μητέρας',
nationality='Υπηκοότητα', adt='Α.Δ.Τ.', password='0cc175b9c0f1b6a831c399e269772661',
dept='biology', id='Αριθμός μητρώου', studying_semester='6', registration_year='2001-00-00',
atlas_id='1234', academicIDNumber='123456789012', perm_address_road='Οδός',
perm_address_number='Αριθμός', perm_address_area='Περιοχή/Πόλη', perm_address_PObox='Τ.Κ.',
perm_address_Country='Χώρα', study_address_road='Οδός', study_address_number='Αριθμός',
study_address_area='Περιοχή/Πόλη', study_address_PObox='Τ.Κ.', study_address_Country='Χώρα',
telephone='+305555555555', cellphone='+305555555555', fax='+305555555555', afm='Α.Φ.Μ.',
eforia='Δ.Ο.Υ.', amka='Α.Μ.Κ.Α.', amika='Α.Μ.ΙΚΑ', status='registered' WHERE email='20@send.com';