2013-05-21 53 views
0

我試圖編寫一個爲商店預留產品的腳本。它應該將數據發送到mysql數據庫,然後返回'shop'中的值。代碼如下: 查看店鋪產品保留腳本PHP

<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> 

這是儲備項目PHP文件

<?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()); 

?> 

它的返回錯誤和不更新。任何幫助是極大的讚賞。

感謝

+1

哪些錯誤? 404? BSOD?內核恐慌? –

回答

0

你試圖將一個字符串(引號括起來$儲備)增加了許多。嘗試在更新查詢刪除引號,即:

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

我試過以上,並感謝您的答案,但無濟於事基本上我試圖通過增加表格中的數量並將其張貼到腳本來更新數量的任何想法更新數量? –

0

變化

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

mysql_query("UPDATE products SET reserve = reserve" . $reserve . " WHERE id ='$id'");