使用PHP的MySQL更新不起作用

时间:2013-09-18 20:29:02

标签: php android mysql

一切正常,只有UPDATE命令不起作用:

$con = mysql_connect($dburl, $dbuser, $dbpass);
if (!$con) {
  die('Could not connect: '.mysql_error());
}
mysql_select_db($dbname, $con);

$result = mysql_query("SELECT * FROM $dbtable WHERE user = '$user'");
$token = generateToken();

if (!empty($result)) {
  // check for empty result
  if (mysql_num_rows($result) > 0) {

    $result = mysql_fetch_array($result);

    if (strcmp($result["pass"], $pass) == 0) {
      $client = array();
      $client["Credential"] = $token;

      mysql_query("UPDATE $table SET credential='$token'
        WHERE user='$user' && pass='$pass'", $con);
      print(json_encode($client));
    }
    else {
      $client["success"] = "0";

      print(json_encode($client));
    }
  }
  else {
    // no product found
    $client["success"] = "0";
    print(json_encode($client));
  }
}
else {
  $client["success"] = "0";
  print(json_encode($client));
}

mysql_close($con);

我需要更新登录中的凭证令牌。问题出现在mysql_query(“UPDATE $ table SET credential ='$ token'WHERE user ='$ user'&& pass ='$ pass'”,$ con);

1 个答案:

答案 0 :(得分:2)

此(第二)行不正确(已在您的问题中编辑/更正,如果同行/已查看/已接受)

// check for empty result
if (mysql_num_rows($result)  0) {