【发布时间】:2014-08-27 17:51:27
【问题描述】:
所以我正在尝试建立一个在线商店,基本上不起作用的是在购买点击“购买”按钮时执行查询。查询是:
$sql = mysql_query("INSERT INTO vehicles (model,owner) VALUES ('$vehid','$id')");
按钮是
<form action=\"\" method=\"post\">
<input type=\"submit\" value=\"BUY\">
</form>
整个代码:
<?php
$id = $_SESSION['SESS_MEMBER_ID'];
include ('config2.php');
$result = mysql_query("select * from shop_vehicule ORDER BY id DESC");
$result2 = mysql_query("select * from accounts where id = '$id'");
while($row = mysql_fetch_array($result2))
$credit = $row['credits'];
while($row = mysql_fetch_array($result)){
$name = $row['nume'];
$price = $row['pret'];
$left = $credit - $price;
$vehid = $row['vehid'];
echo "<p><center><b>$name</b> | $price </center>
<a href=\"#\" class=\"topopup\">More information about $name</a></p>
<div id=\"toPopup\">
<div class=\"close\"></div>
<span class=\"ecs_tooltip\">Press Esc to close <span class=\"arrow\"></span></span>
<div id=\"popup_content\"> <!--your content start-->
<p>
The $name costs $price, after you'll have $left !</p>
<form action=\"\" method=\"post\">
<input type=\"submit\" value=\"BUY\">
</form>
</div>
</div>
<div class=\"loader\"></div>
<div id=\"backgroundPopup\"></div>";
$sql = mysql_query("INSERT INTO vehicles (model,owner) VALUES ('$vehid','$id')");
}
mysql_close();
?>
【问题讨论】:
-
您提出了不好的问题,并有可能失去您的提问权限。 You should read this before you post your next one.
-
mysql_query是一个过时的接口,不应在新应用程序中使用,并将在未来的 PHP 版本中删除。像PDO is not hard to learn 这样的现代替代品。如果您是 PHP 新手,PHP The Right Way 之类的指南可以帮助您解释最佳实践。 -
您提出的这类问题表明缺乏基础知识。您对 PHP 有哪些参考资料?一本好书或参考网站将对您的学习大有帮助。
-
完全同意你@tadman。