Php 如何将mysql中的行与表单中的数量相乘?

Php 如何将mysql中的行与表单中的数量相乘?,php,html,mysql,forms,phpmyadmin,Php,Html,Mysql,Forms,Phpmyadmin,我有以下代码,现在我想在点击“购买”链接后,将$row['Price']乘以表单中的数量。我是一个初学者,所以请不要判断,任何帮助感谢:)谢谢 品名 价格 形象 量 购买 例如,您的表单是这样的 <form method='post' action='thispage.php'> <input type="text" name="quantity" vlaue="1"> <!--you can get this value from form input no

我有以下代码,现在我想在点击“购买”链接后,将$row['Price']乘以表单中的数量。我是一个初学者,所以请不要判断,任何帮助感谢:)谢谢


品名
价格
形象
量
购买


例如,您的表单是这样的

<form method='post' action='thispage.php'>
<input type="text" name="quantity" vlaue="1"> <!--you can get this value from form input no problem -->
</form>
<!-- now on thispage.php write the script you have posted on the question and on line  Buy link you have to do something like that-->
<?php 
@$q = $_POST['quantity']; 
$value= $q*$row['Price'];
?>

echo '<a href="buy.php?id='. $row['ProductID'].'&price='.$value.'">Buy</a>'; 
$value = $_GET['price'];
echo $value;

短版:

您需要发布数量和productID。在your buy.php中,从数据库中获取特定productID的产品价格,并将其乘以数量。不要在你的表格中张贴价格!!!为了便于编程,请不要在表格中公布产品价格

长版本:

您需要的:

1:一张表格(你已经有了) 1b:保存产品ID的隐藏表单字段:

<input type='hidden' name="ProductID" value="<? echo $row['ProductID'];?>"/>
现在您需要从数据库中获取该产品以获取价格

$query="SELECT * FROM products where ProductID=$_POST['ProductID']";
而不是将价格乘以数量

不要在表格中发送价格。。。因为人们可以编辑这个值! 这就是为什么我们只发送产品ID并从数据库中获取价格的原因

还要注意的是,在这个简短的解释中,我没有考虑形式验证。但显然,您需要确保从数据库中获取的数据是有效的,并且没有危险(要了解更多信息,请访问google SQL injection)

<input type='hidden' name="ProductID" value="<? echo $row['ProductID'];?>"/>
<input type='submit' />
echo $_POST['quantity'] ;
echo $_POST['ProductID'] ;
$query="SELECT * FROM products where ProductID=$_POST['ProductID']";