问题描述
我的购物车有问题,希望您能为我解决问题.
我有一个购物车,其中包含一个在数据库中选择值时得到的会话.
我还有一个文本框,其中包含所需的预算.
我的问题是我想显示一条错误消息,该消息可以检测会话的总价格是否大于预算.
这是我的代码,希望您能对我有所帮助
< form method ="get">
预算:
<输入type ="text" name ="budget" class ="txtfield"占位符=请输入所需的预算">
服务类型:
<选择name ="servicetype" class ="txtfield">
< option>婚礼</option>
< option>首次亮相</option>
< option>生日</option>
</select>
<输入类型=提交" name =搜索" value =搜索" class ="btn btn-warning">
</form>
所需金额:
请输入您想要的金额'';
}
其他
{
$ servicetype = $ _GET [''servicetype''];
$ results = $ mysqli-> query("SELECT service_inclusion,price,servicetype,soid FROM service_offer
其中servicetype =''$ servicetype''ORDER BY soid ASC);
如果($ results)
{
while($ obj = $ results-> fetch_object())
{
回声'''';
回声''< form method ="get" action ="cart_update.php">'';
回声''''.$ obj-> service_inclusion.'''';
echo``价格:''.$ currency.$ obj-> price.'''';
echo``服务类型:''.$ obj-> servicetype.'''';
回声'''';
echo''< button style ="background:#F01818; color:white; border:0;">添加服务</button>'';
回声'''';
echo''< input type ="hidden" name ="service_inclusion" value =''.$ obj-> service_inclusion.''"/>'';
回声''< input type ="hidden" name ="type" value ="add"/>'';
回声''< input type ="hidden" name ="soid" value =''.$ obj-> soid.''"/>'';
回声''< input type ="hidden" name ="return_url" value =''.$ current_url.''"/>'';
回声''</form>'';
回声'''';
}
}
}
?>
您的购物车
'';
if($ _ GET [''budget'']> $ cart_itm [''price''])
{
$ message =``错误'';
}
其他
{
foreach($ _SESSION ["products"] as $ cart_itm)
{
回声'''';
回声``×'';
回声''''.$ cart_itm ["name"].''.'';
echo''Price:''.$ currency.$ cart_itm ["price"].''.'';
回声'''';
$ subtotal =($ cart_itm ["price"]);
$ Total =($ total + $ subtotal);
} echo'''';
echo``Total:''.$ currency.$ Total.''退房!'';
回声``空购物车'';
}}
其他
{
回显``您的购物车为空'';
}}
?> ;;
< script type ="text/javascript">
</script>
Hi i have a problem with my shopiing cart i hope you can help me with my problem.
I have a shopping cart which contains a session that i get when selecting values on database.
I have also a textbox which contains a desired budget.
My problem is I want to have a error message which can detect if the total price of the session is greater than the budget.
here is my code I hope you can help me
<form method="get">
Budget:
<input type="text" name="budget" class="txtfield" placeholder="Please enter your desired budget">
Service Type:
<select name="servicetype" class="txtfield">
<option>Wedding</option>
<option>Debut</option>
<option>Birthday</option>
</select>
<input type="submit" name="search" value="Search" class="btn btn-warning">
</form>
Desired Amount:
Please enter your desired amount'';
}
else
{
$servicetype = $_GET[''servicetype''];
$results = $mysqli->query("SELECT service_inclusion,price,servicetype,soid FROM service_offer
where servicetype=''$servicetype'' ORDER BY soid ASC");
if ($results)
{
while($obj = $results->fetch_object())
{
echo '''';
echo ''<form method="get" action="cart_update.php">'';
echo ''''.$obj->service_inclusion.'''';
echo ''Price: ''.$currency.$obj->price.'' '';
echo ''Service Type: ''.$obj->servicetype.'' '';
echo '''';
echo ''<button style="background:#F01818; color:white;border:0;">Add Services</button>'';
echo '''';
echo ''<input type="hidden" name="service_inclusion" value="''.$obj->service_inclusion.''" />'';
echo ''<input type="hidden" name="type" value="add" />'';
echo ''<input type="hidden" name="soid" value="''.$obj->soid.''" />'';
echo ''<input type="hidden" name="return_url" value="''.$current_url.''" />'';
echo ''</form>'';
echo '''';
}
}
}
?>
Your Shopping Cart
'';
if($_GET[''budget''] > $cart_itm[''price''])
{
$message = ''error'';
}
else
{
foreach ($_SESSION["products"] as $cart_itm)
{
echo '''';
echo ''×'';
echo ''''.$cart_itm["name"].'''';
echo ''Price :''.$currency.$cart_itm["price"].'''';
echo '''';
$subtotal = ($cart_itm["price"]);
$Total = ($total + $subtotal);
}echo'''';
echo ''Total : ''.$currency.$Total.'' Check-out!'';
echo ''Empty Cart'';
} }
else
{
echo ''Your Cart is empty'';
}}
?>;
<script type="text/javascript">
</script>
推荐答案
这篇关于如何检测我的总价格是否大于我在文本框中输入的价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!