hi my website have comercial website , my problem is on the quantity post when user add the listing and when user buy the listing i want not allow in the post negative quantity -1 - 3 and 0.111111 example need to be only 1 or high if lower show a error
is the array for the quantity
<?php
$quantityList = array("infinite");
for($i=1;$i<100;$i++){
$quantityList[] = (string)$i;
}
<?
// this is the check when Listing is add by the vendor so maybe here need to check too if the quantity insert is 1 or high and positive not allow -1 -3
if(isset($_REQUEST["quantity"]) && !in_array($_REQUEST["quantity"], $quantityList)){
$quantity_error = "has-error";
$quantity_error_text = "warning";
$anyErrors = true;
}
[/code]
// here big problem members usually can choose from 1 to 99 but someone can modify the post parameters and from 1 he can make this -1 and the server make him buy for free the item
[code]
<div class="form-group <?=$quantity_error;?>">
<label for="quantity">Choose quantity</label>
<select class="form-control" id="quantity" name="quantity">
<?php
foreach($quantityList as $opt){
echo (isset($_REQUEST["quantity"])&&strtolower($_REQUEST["quantity"])==strtolower($opt))?"<option value=\"$opt\" selected=\"selected\">".ucfirst($opt)."</option>":"<option value=\"$opt\">".ucfirst($opt)."</option>";
}
?>
</select>
<span class="help-block"><?=$quantity_error_text;?></span>
</div>
</div>
<?php if($item["quantity"] == "infinite" || $item["quantity"] == "inf" || $item["quantity"]>0){ ?>
<div class="">
<label for="quantity">Qnt in Stock:</label>
<select class="form-control input-sm" name="quantity">
<?php
if($item["quantity"] == "inf"){
for($i = 1; $i<100; $i++)
echo "<option value='$i'>$i</option>";
}else{
for($i = 1; $i<$item["quantity"]+1; $i++)
echo "<option value='$i'>$i</option>";
}
?>
// this is another check but i dont really know
<?php
if(isset($_REQUEST["quantity"]) && is_numeric($_REQUEST["quantity"])){
$_SESSION["order"]["quantity"] = $_REQUEST["quantity"];
$_SESSION["order"]["start_time"] = time();
}
elseif(!isset($_SESSION["order"]["quantity"]) || !is_numeric($_SESSION["order"]["quantity"]))
$pageError = Error404();
?>