简体   繁体   English

Mysql查询成功,但没有更新

[英]Mysql query successful, but not updating

I'm working on an RPG-type battle system for a friend and have run into frustrating issues with a mysql query. 我正在为朋友制作一个RPG型战斗系统,并且遇到了一个令人沮丧的mysql查询问题。 Also, no lectures on the semantics of mysql_ functions, please. 另外,请不要讲授mysql_函数的语义。

$sql = "UPDATE `user_pets` SET `curhp` = `hitpoints`, `curmp` = `misticpower`, `pet_status` = '0' WHERE `id` = '" .$arrayPet['id']. "'";
if ( mysql_query($sql) {
    echo "Success";
}

This comes back as success every time in the application. 这在应用程序中每次都会成功。 However, nothing is actually happening in the database. 但是,数据库中实际上没有发生任何事情。 I've echo'd the query itself and ran it in phpmyadmin and the "healing" is completed properly. 我已经回复了查询本身并在phpmyadmin中运行它并且“愈合”已正确完成。 However, WHATEVER is actually happening when this query executes, it is not what is desired. 但是,当执行此查询时,实际上发生了WHATEVER,这不是所期望的。

Any recommendations for troubleshooting, or can you see anything wrong with the query itself? 有关故障排除的任何建议,或者您是否看到查询本身有任何问题?

$arrayPet['id'] is taken from the user_pets table and is a valid ID. $ arrayPet ['id']取自user_pets表,是一个有效的ID。

First thing I recommend is not wrapping $arrayPet['id'] in single quotes... I'm assuming it's an integer. 我建议的第一件事是不用单引号包装$arrayPet['id'] ...我假设它是一个整数。

Second is if the function mysql_query() returns successfully, it doesn't necessarily mean anything got updated. 第二个是如果函数mysql_query()成功返回,它并不一定意味着任何更新的东西。 It just means the query executed successfully on the server. 它只是意味着在服务器上成功执行了查询。 Your query looks like all it does is set some strings and set pet_status to 0. Please provide: 您的查询看起来就像它设置了一些字符串并将pet_status设置为0.请提供:

  1. An actual sample of a row of the data from user_pets 来自user_pets的一行数据的实际样本
  2. What you expect the row to look like after this query runs 您希望在此查询运行后行看起来像什么

try this: 尝试这个:

$sql = "UPDATE user_pets SET curhp = 'hitpoints', curmp = 'misticpower', pet_status = '0' WHERE id = '" .$arrayPet['id']. "'";
$result = mysql_query($sql);

if ($result) {
echo "Success";

} }

More importantly, check your $arrayPet['id']: does it return an integer or string value? 更重要的是,检查你的$ arrayPet ['id']:它返回一个整数或字符串值吗? If it's an integer type, then don't put it inside single quote. 如果它是整数类型,则不要将其放在单引号内。 Just do something like this: 做这样的事情:

... WHERE id = $arrayPet['id']";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM