【问题标题】:What does this mean? Fatal error: Can't use function return value in write context这是什么意思?致命错误:无法在写入上下文中使用函数返回值
【发布时间】:2017-06-16 21:13:51
【问题描述】:

遇到了 PHP 错误

严重性:编译错误
消息:无法在写入上下文中使用函数返回值
行号:116
floor($BudgetPerPerson) = $TotalBudget / $NumberOfPeople;

label class="heading">How much is your budget? :</label>
<br><br>
<input name="TotalBudget" placeholder="Budget " class="form-control" type="text">
<br><br>
</center>
<!----- Including PHP Script ----->
<label class="heading">How many guest do you intend to invite? :</label>
<br><br>
<input name="NumberOfPeople" placeholder="Number Of People" class="form-control" type="text"><br><br>
</center>
<input type="submit" name="submit" Value="Submit"/>
<!----- Including PHP Script ----->

 <?php

这部分我认为是错误的

$TotalBudget= ($_POST['Budget']);
    $people = ($_POST['NumberOfPeople']);
    $BudgetPerPerson  = $TotalBudget / $people;
//Calculate the Budget Per Person

$BudgetPerPerson = floor($TotalBudget / $NumberOfPeople);



//The $BudgetPerPersonmust now fit a package price
if($BudgetPerPerson == "17") {
echo "You have Package A";
}
elseif($BudgetPerPerson == "19") {
echo "You have Package B";
}
if($BudgetPerPerson == "22") {
echo "You have Package C";
}
if($BudgetPerPerson == "20") {
echo "You have Package D";
}
if($BudgetPerPerson == "25") {
echo "You have Package E";
}
//Since Package D is the most expensive, if the $BudgetPerPerson is equal to or higher than 20 it will automatically select Package D
elseif($BudgetPerPerson >= "27") {
echo "You have Package F";
}
else {
//This code will execute when the price per package is too low
echo "The amount of people is too high for the budget, please increase your budget or reduce the number of people to receive a package quotation.";
}else {
//Calculate the Difference between the lowest package price and the offered price
ceil($Difference) = ((17 - $BudgetPerPerson) * $NumberOfPeople)
//This code will execute when the price per package is too low
echo "Your budget is too low for the amount of people. Please increase your budget by: $" . $Difference . " to be able to reserve a package";
}

?>

【问题讨论】:

  • 您可能无法像现在尝试为函数的结果分配一个数字 - 我投票关闭

标签: php html forms


【解决方案1】:

你需要改写:

$BudgetPerPerson = floor($TotalBudget / $NumberOfPeople);

关于第二个问题,错误如下:

$TotalBudget= ($_POST['Budget']);
$people = ($_POST['NumberOfPeople']);
$BudgetPerPerson  = $TotalBudget / $people;
//Calculate the Budget Per Person

$BudgetPerPerson = floor($TotalBudget / $NumberOfPeople);

您的变量名为 $people 而不是 $NumberOfPeople

改成这样:

$TotalBudget= ($_POST['Budget']);
$people = ($_POST['NumberOfPeople']);
//Calculate the Budget Per Person
$BudgetPerPerson  = floor($TotalBudget / $people);

【讨论】:

  • 对不起,我的编码不太好。你能告诉我如何声明这个变量吗? $BudgetPerPerson = floor($TotalBudget / $NumberOfPeople);因为我收到一个错误,说未定义的变量。
  • @ZureenFarisya 这意味着 $TotalBudget$NumberOfPeople 或两者都不存在于您的代码中,或者没有值。但是,这是另一个问题,您需要显示更多代码。
  • 这里我给出完整的编码
  • @ZureenFarisya 为您的第二个问题编辑了答案
  • 我不明白。
【解决方案2】:

您在作业的左侧使用了一个函数。

【讨论】:

    猜你喜欢
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-03
    • 2011-08-07
    • 1970-01-01
    相关资源
    最近更新 更多