如果值发生变化,如何更新多行? 我从我的MYSQL数据库中包含超过130行和相同数字的XML文件中导出数据,我想比较它并插入如果有新行并更新更改的行。
注意:插入新行正常,但更新不起作用!
$query = "SELECT positionid FROM vacant WHERE positionid = '".$position."' and ptitle = '".$ptitle."' and location = '".$location."' and vacantd = '".$vdate."' and candidate = '".$resultcandidate."' and cv = '".$cvtorsaf."'";
$sql = mysql_query($query);
if (!$sql) { // add this check.
die('Invalid query: ' . mysql_error());
}
$recResult = mysql_fetch_array($sql);
$existName = $recResult["positionid"];
if($existName=="") {
$insertTable= mysql_query("insert into vacant (positionid, ptitle, location, vacantd, candidate, cv) values('".$position."', '".$ptitle."', '".$location."', '".$vdate."', '".$resultcandidate."', '".$cvtorsaf."');");
} else {
$insertTable= mysql_query("UPDATE vacant SET ptitle = '".$ptitle."', location = '".$location."', vacantd = '".$vdate."', candidate = '".$resultcandidate."', cv = '".$cvtorsaf."' WHERE positionid = '".$position."'");
}

答案 0 :(得分:1)
如果您在更新字段中有code
error
仍然正常
然后尝试print
您的error
。使用mysql_error();
$insertTable= mysql_query("UPDATE vacant SET ptitle = '".$ptitle."', location = '".$location."', vacantd = '".$vdate."', candidate = '".$resultcandidate."', cv = '".$cvtorsaf."' WHERE positionid = '".$position."'") or print_r(mysql_error());die;