简体   繁体   English

Mysql数据库没有更新

[英]Mysql Database Isn't Updating

Okay so users on my game have a page. 好吧,我的游戏用户有一个页面。 Other users can comment on the page. 其他用户可以在页面上发表评论。 I made a script to where the user can set it to where people can comment on their wall or if it's disabled. 我制作了一个脚本,用户可以将其设置为人们可以在墙上发表评论或者是否已禁用的地方。 If I manually change the database it works, but I have it setup with radio buttons and it's not updating. 如果我手动更改数据库它可以工作,但我设置了单选按钮,它没有更新。 Here's the form. 这是表格。

<form action="settings" method="post">
Comments: <br />
Enabled:  
<input type="radio" name="change_wall" id="change_wall" value="no" checked="checked" />
<br />
Disabled: 
<input type="radio" name="change_wall" id="change_wall" value="yes" />
<br />
<input type="submit" value="Change" />
</form>

Below this is the SQL of the database updating. 下面是数据库更新的SQL。

    <?php
    if ( isset ( $_POST['change_wall'] ) )
        {
        $change_wall = mysql_real_escape_string($_POST['change_wall']); 
        if ($cash >= 5000) {
        $sql = "UPDATE users SET disable_wall='".$change_wall."' , cash=(cash - 5000) WHERE id='".$id."'";
        $res = mysql_query($sql);
            echo  
            '<table width="800" align="center" class="SettingsTable">
              <tr>
                <td>You sucessfully changed your comment settings!</td>
              </tr>
            </table>
            <br />';
        }
        else  {
            echo 
            '<table width="800" align="center" class="SettingsTable">
              <tr>
                <td>You don\'t have enough cash to change your comment settings!</td>
              </tr>
            </table>
            <br />'; 
        }
        }
?> 

Here's the coding for the user's page to display their comments or if it's disabled. 这是用户页面的编码,用于显示他们的评论或是否被禁用。

  <?php 
      if ($disable_wall = 0) { 
        include 'users_wall.php';
      }
      elseif ($disable_wall = 1) {
          echo 
          '<table width="800" align="center" class="DisabledWall">
          <tr>
            <td>' . $userp['name'] . '\'s ' . 'Comments Disabled!</td>
          </tr>
        </table>';
      }
    ?>

first of all, be sure that the sql query is executed - $cash is really >= 5000 and $id variable consists proper value 首先,确保执行sql查询 - $ cash确实> = 5000且$ id变量包含正确的值

then, what type does the table field 'disable_wall' have? 那么,表字段'disable_wall'有什么类型? varchar or enum? varchar还是enum? not int? 不是int?

if instructions above didnt help, type this after last line of your script: 如果上面的说明没有帮助,请在脚本的最后一行后输入:

die("error: ".mysql_error());

submit the form and watch, what error happened while you are updating the table 提交表单并观察,更新表时发生了什么错误

Because you need a boolean (yes/no) response, you can simply set them to 0 or 1, to be safe. 因为你需要一个布尔(是/否)响应,你可以简单地将它们设置为0或1,以确保安全。
To answer your question, do 要回答你的问题,请做


  $sql = "UPDATE users SET disable_wall='1' , cash=(cash - 5000);
 

And to disable the wall 并禁用墙


  $sql = "UPDATE users SET disable_wall='0' , cash=(cash - 5000);
 

Better yet, use a boolean column for it. 更好的是,为它使用布尔列。

Also, ensure that $id is a valid value, and currently has at least a row in the table. 另外,请确保$ id是有效值,并且当前表中至少有一行。

More importantly, use PDO or MySQLi; 更重要的是,使用PDO或MySQLi; MySQL extensions are already deprecated. MySQL扩展已被弃用。

Hope this helps. 希望这可以帮助。

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

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