+/-具有单个文本字段的等式

时间:2013-08-21 09:58:33

标签: php html equation

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

the layout of the storage system

我不知道是否可以这样做,就像我想要的那样简单:) 但无论如何,这是目前为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中不支持的操作数类型

1 个答案:

答案 0 :(得分:0)

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

$assoc = mysql_fetch_assoc($sql);

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

$v_nu = $v_stk + $assoc['v_stk'];