Wednesday, 21 August 2013

+/- equation with a single textfield

+/- equation with a single textfield

I am making a very simple storage system, and i want to make it so that
the user puts a number in the box, and press the + or - button, to add or
subtract.

I don't know if it's even possible to do it, as simple as i wanted it to
be :) but anyway, here is the code so far for 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 }; ?>
and here is for 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");
?>
I don't know if it is remotely close to something that would work, but
with this code it gives me: Fatal error: Unsupported operand types in
C:\wamp\www\lager\index_sql.php on line 8

No comments:

Post a Comment