货币符号与价格验证字段冲突


Currency symbol conflicting price validation field

我把美元放在每个价格(数字)之前

 $Product_Price="USD".mysql_real_escape_string($_POST['product_price']);

现在我验证它为

if(!is_numeric($Product_Price))
        {
            $Errormessage[]="Price must be in numbers";
        }

正在运行if语句。我怎么能从每个价格中获得美元,但对于用户来说,应该限制他只能添加数字。

您可以在添加"USD"前缀之前检查该值是否为数字。

这样的…

if(is_numeric($Product_Price))
{
    $Product_Price="USD".mysql_real_escape_string($_POST['product_price']);
}
else
{
    $Errormessage[]="Price must be in numbers";
}

$price = mysql_real_escape_string($_POST['product_price']);
$currency = mysql_real_escape_string($_POST['product_currency']);
if (is_numeric($price))
{
  // insert price and currency in separate columns
}
else
{
  // error message
}