2017-06-16 57 views
-4

一个PHP错误遇到这是什么意思?致命错误:在写情况下不能使用函数的返回值

Severity: Compile Error
Message: Can't use function return value in write context
line number: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 

this part i think is wrong

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

?> 
+2

你可能不会像现在正在尝试的那样为一个函数的结果指定一个数字 - 我投票结束 – mplungjan

回答

3

你需要把它写不同:

$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); 
+0

对不起,我不擅长编码。你能告诉我如何声明这个变量。 $ BudgetPerPerson = floor($ TotalBudget/$ NumberOfPeople);因为我得到一个错误说未定义的变量。 –

+0

@ZureenFarisya这意味着'$ TotalBudget'或'$ NumberOfPeople'或两者都不存在于您的代码中,或者没有值。但是,这是另一个问题,您需要展示更多代码。 – FMashiro

+0

在这里我给全编码 –

0

您在赋值的左侧使用的功能。

相关问题