0
我正在使用foreach循环来检查并插入新标签。为什么这个if else条件无法正常工作?
但是两个条件(if和alse)同时应用,而不管mysql发现的id是否等于foreach发布的ID。 PLZ帮助
$new_tags = $_POST['new_tags']; //forget the mysl security for the time being
foreach ($new_tags as $fnew_tags)
{
$sqlq = mysqli_query($db3->connection, "select * from o4_tags limit 1");
while($rowq = mysqli_fetch_array($sqlq)) {
$id = $rowq['id'];
if($id == $fnew_tags) { //if ID of the tag is matched then do not insert the new tags but only add the user refrence to that ID
mysqli_query($db3->connection, "insert into user_interests(uid,tag_name,exp_tags) values('$session->userid','$fnew_tags','1')");
}
else
{ //if ID of the tag is not matched then insert the new tags as well as add the user refrence to that ID
$r = mysqli_query($db3->connection, "insert into o4_tags(tag_name,ug_tags,exp_tags) values('$fnew_tags','1','1')");
$mid_ne = mysqli_insert_id($db3->connection);
mysqli_query($db3->connection, "insert into user_interests(uid,tag_name,exp_tags) values('$session->userid','$mid_ne','1')");
}
}
}
我不认为if/else的两个部分都实际执行。尝试仅在控制台而不是查询中打印某些内容,这很可能是if/else内部代码中的错误。 – sashkello 2013-04-10 03:21:05
尝试在检查前打印$ id $ fnew_tags值 – PSR 2013-04-10 03:22:21