Php 比较数据sql

Php 比较数据sql,php,mysql,Php,Mysql,我有这样的php代码 $result = mysql_query("SELECT phone FROM user where phone LIKE 'hjkhkjh'); // check if row inserted or not if ($result) { // successfully inserted into database $response["success"] = 1; $response["message"] = "Account wasnt

我有这样的php代码

$result = mysql_query("SELECT phone FROM user where phone LIKE 'hjkhkjh');


// check if row inserted or not
if ($result) {
    // successfully inserted into database
    $response["success"] = 1;
    $response["message"] = "Account wasnt created.";

    // echoing JSON response
    echo json_encode($response);
}
else  {
    // failed to insert row
    $response["success"] = 0;
    $response["message"] = "Account was created.";
我想比较数据库中的电话号码,但当我运行此代码时,此代码显示“account wasnt created”,而我的表中有数据电话号码“hjkhkjh”,谢谢我的代码的任何解决方案,因为当if构造解析为true时,您正在编写“account wasnt created”。 像这样试试

if ($result) {
    // successfully inserted into database
    $response["success"] = 1;
    $response["message"] = "Account was created.";

    // echoing JSON response
    echo json_encode($response);
}
else  {
    // failed to insert row
    $response["success"] = 0;
    $response["message"] = "Account wasnt created.";
说:

用于选择、显示、描述、解释和其他返回语句 resultset,mysql_query()在成功时返回资源,在失败时返回FALSE 错误

由于查询不会产生错误,所以返回的是资源,它传递
if($result){

(不管db表中是否有类似于“HJKKJH”的phone的条目)

我找到了解决方案,我更改代码如下 $result=mysql_query(“从用户那里选择电话,电话='HJKKJH'”)


谢谢大家:D

切换$response[“message”]'s to it's correct location$result在执行查询时被计算为true,而您将其解释为帐户未创建?我觉得这似乎是一个逻辑错误。此外,这是一个选择,而不是插入。他可能想检查插入是否成功。我想。这仍然不是最简单的方法…您还使用了比如不向变量添加任何通配符。在这种情况下,您最好只使用
=
。对不起,我想问一下,如果我们想选择查询而不是插入,那么如何使用代码?因为代码$result=mysql\u query(“从用户那里选择电话,如'hjkhkjh');这是用于插入的,对吗?如果有记录,$result将解析为true,例如查询成功。实际上我想问的是如何在php中检查和比较数据。如果我有数据'phone='hjkhkjh',我想显示该帐户是创建的。但是如果数据库中找不到数据电话'hjkhkjh',我想显示该帐户不是c重新命名。
// check if row inserted or not
if($row = mysql_fetch_array($result)){
    // successfully inserted into database
    $response["success"] = 1;
    $response["message"] = "Account was created.";

    // echoing JSON response
    echo json_encode($response);
}
else  {
    // failed to insert row
    $response["success"] = 0;
    $response["message"] = "Account wasnt created.";

    // echoing JSON response
    echo json_encode($response);
}