if (!!$data = _mysql_fetch("SELECT 
`tg_id` 
FROM 
`tg_friends`
WHERE 
(`tg_toUser` = '{$clean['toUser']}' AND `tg_fromUser` = '{$clean['fromUser']}')
OR 
(`tg_toUser` = '{$clean['fromUser']}' AND `tg_fromUser` = '{$clean['toUser']}')
")){
//back_result("已经是好友,无需添加");
print_r($data);
} else {
_mysql_query("INSERT INTO 
`tg_friends` 
(
`tg_toUser`,
`tg_fromUser`,
`tg_content`,
`tg_date`
 )
 VALUES 
(
'{$clean['toUser']}',
'{$clean['fromUser']}',
'{$clean['content']}',
NOW()
 )
");
if (_affected_rows() == 1){
sessionDestory();
back_result("好友添加成功,请等待验证");
} else {
sessionDestory();
back_result("好友添加失败");
}
}
这是部分代码,当我首次添加好友的时候,系统就告诉我已经添加了.查看数据库,多了一条tg_toUser,tg_fromUser都为空的数据,求解

解决方案 »

  1.   

    问题自己瞎弄解决了,但有一点不明白,还望解答.
    if (!!$uniqid){
    include  $path.'\register.func.php';
    _uniqid($uniqid['tg_uniqid'], $_COOKIE['uniqid']);
    $clean = array();
    $clean['toUser'] = $_POST['toUserName'];
    $clean['fromUser'] = $_COOKIE['username'];
    $clean['content'] = contentCheck($_POST['content']);
    $clean = mysql_string($clean);
    if (!!$data = _mysql_fetch("SELECT 
    `tg_id` 
    FROM 
    `tg_friends`
    WHERE 
    (`tg_toUser` = '{$clean['toUser']}' AND `tg_fromUser` = '{$clean['fromUser']}')
    OR 
    (`tg_toUser` = '{$clean['fromUser']}' AND `tg_fromUser` = '{$clean['toUser']}')
    ")){
    back_result("已经是好友,无需添加");
    } else {
    _mysql_query("INSERT INTO 
    `tg_friends` 
    (
    `tg_toUser`,
    `tg_fromUser`,
    `tg_content`,
    `tg_date`
     )
     VALUES 
    (
    '{$clean['toUser']}',
    '{$clean['fromUser']}',
    '{$clean['content']}',
    NOW()
     )
    ");
    if (_affected_rows() == 1){
    sessionDestory();
    back_result("好友添加成功,请等待验证");
    } else {
    sessionDestory();
    back_result("好友添加失败");
    }
    }
    } else {
    back_result("唯一标识符异常");
    }
      

  2.   

    问题自己瞎弄解决了,但有一点不明白,还望解答.
    下面这么写没问题if ($_GET['action'] == 'add'){
    checkCode($_POST['checkCode'],$_SESSION['code']);
    $uniqid = _mysql_fetch("SELECT 
    `tg_uniqid` 
    FROM 
    `tg_user` 
      WHERE 
       `tg_username` = '{$_COOKIE['username']}'
     ");
    if (!!$uniqid){
    include  $path.'\register.func.php';
    _uniqid($uniqid['tg_uniqid'], $_COOKIE['uniqid']);
    $clean = array();
    $clean['toUser'] = $_POST['toUserName'];
    $clean['fromUser'] = $_COOKIE['username'];
    $clean['content'] = contentCheck($_POST['content']);

    $clean = mysql_string($clean);
    if (!!$data = _mysql_fetch("SELECT 
    `tg_id` 
    FROM 
    `tg_friends`
    WHERE 
    (`tg_toUser` = '{$clean['toUser']}' AND `tg_fromUser` = '{$clean['fromUser']}')
    OR 
    (`tg_toUser` = '{$clean['fromUser']}' AND `tg_fromUser` = '{$clean['toUser']}')
    ")){
    back_result("已经是好友,无需添加");
    } else {
    _mysql_query("INSERT INTO 
    `tg_friends` 
    (
    `tg_toUser`,
    `tg_fromUser`,
    `tg_content`,
    `tg_date`
     )
     VALUES 
    (
    '{$clean['toUser']}',
    '{$clean['fromUser']}',
    '{$clean['content']}',
    NOW()
     )
    ");
    if (_affected_rows() == 1){
    sessionDestory();
    back_result("好友添加成功,请等待验证");
    } else {
    sessionDestory();
    back_result("好友添加失败");
    }
    }

    } else {
    back_result("唯一标识符异常");
    }
    }但是,这么些就有问题if ($_GET['action'] == 'add'){
    checkCode($_POST['checkCode'],$_SESSION['code']);
    $uniqid = _mysql_fetch("SELECT 
    `tg_uniqid` 
    FROM 
    `tg_user` 
      WHERE 
       `tg_username` = '{$_COOKIE['username']}'
     ");
    if (!!$uniqid){
    include  $path.'\register.func.php';
    _uniqid($uniqid['tg_uniqid'], $_COOKIE['uniqid']);
    $clean = array();
    $clean['toUser'] = $_POST['toUserName'];
    $clean['fromUser'] = $_COOKIE['username'];
    $clean['content'] = contentCheck($_POST['content']);
    $clean = mysql_string($clean);

    } else {
    back_result("唯一标识符异常");
    }
    }
    if ($_GET['action'] == 'add'){
    checkCode($_POST['checkCode'],$_SESSION['code']);
    $uniqid = _mysql_fetch("SELECT 
    `tg_uniqid` 
    FROM 
    `tg_user` 
      WHERE 
       `tg_username` = '{$_COOKIE['username']}'
     ");
    if (!!$uniqid){
    include  $path.'\register.func.php';
    _uniqid($uniqid['tg_uniqid'], $_COOKIE['uniqid']);
    $clean = array();
    $clean['toUser'] = $_POST['toUserName'];
    $clean['fromUser'] = $_COOKIE['username'];
    $clean['content'] = contentCheck($_POST['content']);
    $clean = mysql_string($clean);
    if (!!$data = _mysql_fetch("SELECT 
    `tg_id` 
    FROM 
    `tg_friends`
    WHERE 
    (`tg_toUser` = '{$clean['toUser']}' AND `tg_fromUser` = '{$clean['fromUser']}')
    OR 
    (`tg_toUser` = '{$clean['fromUser']}' AND `tg_fromUser` = '{$clean['toUser']}')
    ")){
    back_result("已经是好友,无需添加");
    } else {
    _mysql_query("INSERT INTO 
    `tg_friends` 
    (
    `tg_toUser`,
    `tg_fromUser`,
    `tg_content`,
    `tg_date`
     )
     VALUES 
    (
    '{$clean['toUser']}',
    '{$clean['fromUser']}',
    '{$clean['content']}',
    NOW()
     )
    ");
    if (_affected_rows() == 1){
    sessionDestory();
    back_result("好友添加成功,请等待验证");
    } else {
    sessionDestory();
    back_result("好友添加失败");
    }
    }
    } else {
    back_result("唯一标识符异常");
    }
    }

    这样执行会生成一个空数据条.
    简单地说,区别就是加色判断放在另一个判断后再执行.我觉得会不会是因为$clean这个数据数组是在第一个判断中定义的,所以在第二个判断中就不能用的原因.
      

  3.   

    这是不正常的代码这是正常的
    [img=http://hi.csdn.net/attachment/201105/1/9963373_1304248721jlIq.png][/img