我一直在尝试比较两个字符串,一个是用户输入的用户名,另一个是我的程序从数据库中提取的数据。这是我的PHP代码:
$sqlCheck = "SELECT Username FROM location WHERE Username ='$usernamebeingreq'" ;
$result2 = mysqli_query($con, $sqlCheck);
$result2 = mysql_fetch_array($result2);
$resultCheck = false;
//mysqli_query($con, $sqlCheck);
if((strcmp($result2, $usernamebeingreq) == 1))
{
$sql="INSERT INTO pending_req (fromUser, toUser) VALUES ('$username', '$usernamebeingreq')";
$resultCheck = true;
}
答案 0 :(得分:2)
你不能像这样组合mysql_和mysqli_。 此外,您需要遍历结果集以获取值并进行比较:
$result2 = mysqli_query($con, $sqlCheck);
while ($row2 = mysqli_fetch_array($result2))
{
$username_to_check = $row2['Username'];
}
$resultCheck = false;
if((strcmp($username_to_check , $usernamebeingreq) == 1))
/* rest of your code */
有关mysqli_fetch_ functions的更多信息:http://php.net/manual/en/mysqli-result.fetch-array.php