gpt4 book ai didi

php - 使用表单中的输入将值选择到变量中

转载 作者:行者123 更新时间:2023-11-29 23:44:39 24 4
gpt4 key购买 nike

您好,我在从表中选择一个值到 PHP 中的变量中时遇到问题,以便我可以计算某些东西的成本

这是我到目前为止的代码,我希望能够从表C_price中选择一个“成本”值,其中I_type的值a_type 匹配

例如表结构如下所示

ID=1,A_type=line,I_type=Head,cost=5

如果在表格中我输入行和头我需要能够将值 5 放入一个可用于计算的值中并插入到另一个表中,也就是我需要以某种方式将成本放入变量中

以下是我的尝试,我需要帮助,我对这一切都是新手,所以请帮助

$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;
}

最佳答案

你不能同时使用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'";

关于php - 使用表单中的输入将值选择到变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26009095/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com