您好我在将表格中的值选择到PHP中的变量时遇到问题,以便我可以计算某些内容的成本
这是我到目前为止的代码我希望能够选择"成本" C_price
和I_type
的值匹配的表a_type
中的值
例如表结构如下所示
ID=1,A_type=line,I_type=Head,cost=5
如果在表格上我输入了行和头 我需要能够获得价值5到一个古老的我可以在计算中使用并插入另一个表AKA我需要以某种方式将成本转化为变量
以下是我的尝试,我需要新的帮助,所以请帮助
$E_C;
$T_cost = "1";
$date = date("d.m.y");
$name = $_POST["from"];
$email = $_POST["email"];
$ref = $_POST["link"];
$i_type = $_POST["i_type"];
$a_type = $_POST["a_type"];
$extra = $_POST["extra"];
$des = $_POST["description"];
$BG = $_POST["BG"];
$bg_type = $_POST["BGtype"];
$msg = $_POST["message"];
$auto_reply = ("thanks for the email we will get back to you as soon as we can about the cost and how you can pay");
$msg = wordwrap($msg, 70);
$host = "localhost";// hostname
$USER = "root";// username
$PASS = "Password";// password
$DBNAME = "andrea";// databace name
$tbl_name = "c_price";// table name
$con = mysqli_connect("localhost", $USER, $PASS, $DBNAME)or die("mySQL server connection failed");
$all = "SELECT cost FROM C_price WHERE a_type=$a_type,i_type=$i_type";
$result = mysqli_query($con,$all) or die("Error getting total storse");
while($row = mysqli_fetch_array($result))
{
echo $row['cost'];
}
if ($a_type = 'waist' && $extra='Y')
{
$E_C = $cost * .3;
}
elseif ($a_type = 'knee' && $extra='Y')
{
$E_C = $cost * .35;
}
elseif ($a_type ='full' && $extra='Y')
{
$E_C = $cost * .4;
}
else
{
$E_C = 0;
}
$T_cost = $cost + $E_C;
if ($BG = 'y')
{
$T_cost = $T_cost + 10;
}
答案 0 :(得分:0)
你不能同时使用mysqli和mysql .. Mysqli是一个类......所以先改变一下......
while($row = mysqli_fetch_array($result))
{
echo $row['cost'];
}
$news1 = mysqli_result($result, 0); // 0 is the index of the field, not the row
echo $news1;
echo $cost;`
查询应该是这样的......
$all = "SELECT cost FROM C_price WHERE a_type='$a_type'and i_type='$i_type'";
答案 1 :(得分:0)
你不能混合使用mysql和mysqli
更改此行在while循环中添加错误mysqli_error
$news1 = mysql_result($result, 0);
$news1 = mysqli_result($result) or die(mysqli_error());
并且您的查询错误以及和 A_type与A_type不同,同样适用于I_type
$all = "SELECT cost FROM C_price WHERE a_type=$a_type,i_type=$i_type";
//Change it to
$all = "SELECT cost FROM C_price WHERE A_type='$a_type'and I_type='$i_type'";
//和A_type与a_type不同,I_type也是如此