Short explain what I want to do.. when I click my button "calc1" my inputs number(quantity1) should be reduced by the inputs number I type in (amount1) Like " Result = quantity1 - amount1 ". In the input "quantity1" is already a value because I loaded it from my database into the input but the calculation doesn't work. I hope you understand me a bit..I better show my code now..
Calculation code:
<?php
include_once('connect.php');
if($_POST['calc1']){
$_POST['quantity1'] = $_POST['quantity1'] - $_POST['amount1'];
$sql = "UPDATE
tbl_auction
SET
quantity1 = $_POST['quantity1']
WHERE
id = :user_id";
$query = $conn->prepare($sql);
$query ->execute(array('quantity1' => $_POST['quantity1'] ));
} else{
echo 'ups, error!';
}
?>
HTML Code:
<div id="move_amount">
<input type="text" class="amount" name="amount1">
</div>
<div id="move_quantity">
<input type="text" class="tend_quantity" name="quantity1" value=" <?=$value_quantity1 ?>" >
</div>
<div id="move_btn">
<input class="btn_sel" name="calc1" type="submit" name="submitted" value="Bidding">
</div>
Here is the part from my database that I want to update
id AUTO_INCREMENT
quantity1 int(11)
I appreciate every help!
EDIT: My user_id declaration:
if ($result[0]["password"] !== md5($_POST['password'].'D6tp'.$_POST['email'])) {
header('Location: /PHP/index.php?page=login');
} else {
$_SESSION['loged_in'] = true;
$_SESSION['user_id'] = $result[0]["id"];
header('Location: /PHP');
};
EDIT: The Problem is solved! For those who want to know what the issue was: So first @arkascha had some good corrections you can see her post... and the secound issue was because in my inputs value was a string written and that's why the calculation did not work too. Thanks to @arkascha!
$_POST['quantity1'and$_POST['amount1']in a variable?<?php $_GET['q'] = $_GET['q'] - $_GET['a']; echo $_GET['q']; ?>Suppose, the name of the file is: test.php. Then, open localhost/test.php?q=3&a=1. You'll see '2' on that page. Check this: wtf.usa.cc/sof2.php?q=3&a=1md5()hashing algorithm is very insecure to store passwords. It can be easily cracked once the hashes got stolen. You should port to a better implementation. This is the best php based implementation I found so far, though it needs some polishing: defuse.ca/php-pbkdf2.htm and this is a readworthy introduction: crackstation.net/hashing-security.htm