1

我正在制作一个非常简单的存储系统,我想让它让用户在框中输入一个数字,然后按 + 或 - 按钮进行加减。

存储系统布局

我不知道是否有可能做到这一点,就像我想要的那样简单:) 但无论如何,这里是 index.php 的代码

    <?php $v_stk = "v_stk" ?>
    <form action="index_sql.php" method="POST">
    <input name="v_id" type="hidden" value="<?php echo $v_assoc["v_id"] ?>" />
    <input name="v_stk" type="textfield" size="8" />
    <input name="+" type="submit" value="+" style="height:23px; width:35px;" />
    <input name="-" type="submit" value="-" style="height:23px; width:35px;" />
    </form>
    <td class="width50 sidepadding">
    <?php echo $v_assoc["v_stk"]; ?></td>           
    <?php }; ?>

这是 index_sql.php

    <?php
    require("db/db.php");

    $v_id = mysql_real_escape_string($_POST["v_id"]);
    $v_stk = mysql_real_escape_string($_POST["v_stk"]);
    $sql = mysql_query("SELECT v_stk FROM vare WHERE v_id = '$v_id'");
    $assoc = mysql_fetch_assoc($sql);
    $v_nu = $v_stk + $assoc;

    mysql_query("UPDATE vare SET v_nu = '$v_stk' WHERE v_id = '$v_id'");
    header("location: index.php");
    ?>

我不知道它是否离可行的东西很近,但是使用此代码,它给了我:致命错误:第 8 行的 C:\wamp\www\lager\index_sql.php 中不支持的操作数类型

4

1 回答 1

0

因为,您正在使用数组类型变量执行加法。

$assoc = mysql_fetch_assoc($sql);

这里, $assoc 是一个数组变量,所以试试这样,

$v_nu = $v_stk + $assoc['v_stk'];
于 2013-08-21T10:08:07.917 回答