如果值发生变化,如何更新多个行?我从包含130多行和MYSQL数据库中相同编号的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."'");
}
发布于 2016-07-29 12:33:26
嗨,如果您在更新字段中有error,您的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;https://stackoverflow.com/questions/38657942
复制相似问题