如果值发生变化,我如何更新多行? 我从 XML 文件中导出数据,该文件包含超过 130 行且与我的 MYSQL 数据库上的行数相同,我想对其进行比较,如果有新行则插入并更新更改的行。
注意:插入新行工作正常,但更新不起作用!
$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."'");
}
最佳答案
你好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;
关于php - 用不同的值更新现有表,PHP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38657942/