dongyin8009 2013-05-21 13:47
浏览 7

产品保留脚本PHP

I'm trying to code a script that reserves products for a shop. It should work by sending the data to the mysql database and then it returns the values in the 'shop'. The code is as follows; Viewing the shop

<form action="reserveitems3.php" method="POST">
<?php 



// Connects to your Database 
 mysql_connect("localhost", "dbname", "password") or die(mysql_error()) ; 
 mysql_select_db("dbname") or die(mysql_error()) ; 

 //Retrieves data from MySQL 
 $data = mysql_query("SELECT * FROM products") or die(mysql_error()); 

//Puts it into an array 
while($info = mysql_fetch_array( $data )) { 



// render each dtabase result and wrap in a div
echo "<div class='product'>";
echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
echo "<tr>
<td class='image'><img src=http://my-creativewebfusion.com/mysql_data/file/".$info['photo'] . "></td>
<td class='name'>".$info['name'] . "<br/><br/>".$info['desc'] . "</td>
<td class='phone'><input name='".$info['id']."' type='checkbox' value='yes' style='position:relative;float:right;right:50px;' class='checked' onclick='document.getElementById('other').innerHTML = 'Check Box = ' + this.checked;'/><br/><br/>
<div class='alignright'>Price:&nbsp;".$info['price'] . "</div>
<div class='alignright'>QTY:&nbsp;<input type='text' name='reserve' style='width:40px;'/></div>

<div class='alignright'> ";

$sum_total = $info['stock']  - $info['reserve'] ;


if ($sum_total == 0)
{
echo "<p style='color:red;'>Out of stock</p>";
}
        else
{


        echo "<p style='color:green;float:right;'>",($sum_total),"&nbsp;&nbsp;In stock</p>&nbsp;";
         echo "<p style='color:green;'>".$info['reserve']."&nbsp;Reserved</p>";

}

echo "</div></td></tr>";
echo "</table>";
echo "</div><input type='submit' value='Submit' />";
}
?> 

</form>

This is the reserve item php file

<?php 



 // Connects to your Database 
 mysql_connect("localhost", "dbname", "password") or die(mysql_error()) ; 
 mysql_select_db("dbname") or die(mysql_error()) ; 

 //This gets all the other information from the form 

$reserve=$_POST['reserve'];

 //Writes the information to the database 
  mysql_query("UPDATE products SET reserve= reserve + '$reserve' WHERE id ='$id'");



   $result = mysql_query($sql) or die(mysql_error());

 ?> 

It's returning errors and not updating. Any help is greatly appreciated.

Thanks

  • 写回答

2条回答 默认 最新

  • drxdn40242 2013-05-21 13:50
    关注

    You're trying to add a string ($reserve enclosed in quotes) to a number. Try removing the quotes in the update query, i.e.:

    mysql_query("UPDATE products SET reserve= reserve + $reserve WHERE id ='$id'");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错