我如何改变我的PHP代码,所以它可以回应“如果该项目刚刚被创建或更新?”
$query_item_create = "INSERT INTO `item` (`category_id`, `id`) VALUES ('$catid', '$id')";
$query_item_update = "UPDATE `item` SET `date`='$date',`info`='$info' WHERE `id`='$id'";
mysql_query($query_item_create);
mysql_query($query_item_update);
答案 0 :(得分:2)
以下更好地解释:http://php.net/manual/en/function.mysql-affected-rows.php
$affected = mysql_affected_rows();
if($affected > 0)
echo "row was updated/inserted";
else
echo "No rows were ....";