我试图用简单的数学计算,但我无法得到下面的表格进行计算并输出结果。不幸的是,我是个新手。怎么了?
<?php
add_action( \'wp_dashboard_setup\', \'register_my_dashboard_widget\' );
function register_my_dashboard_widget() {
wp_add_dashboard_widget(
\'net_profit_widget\',
\'Net Profit Calculator\',
\'net_profit_widget_display\'
);
}
function net_profit_widget_display() {
$subrice = $_POST[\'subrice\'];
$subnumb = $_POST[\'subnumb\'];
$payperc = "2.9";
$paystan = "0.3";
$netprof = "N/A";
$expense = "N/A";
if (!$subrice="" || !$subnumb="") {
die("Please fill in all the required information!");
//exit();
} else {
if(isset($_POST[\'submit\'])) {
$expense = $_POST[subrice] * (($payperc / 100) + $paystan);
$netprof = ($_POST[subprice] - $expense) * $_POST[subnumb];
}
}
?>
<div style="color: #777;">Paypal fee per transaction: 2.9% + $0.3</div><br>
<form class="netcalc" method="POST" action="">
<label for="sub-price">Subscription Price($)</label><input id="sub-price" type="text" value="<?php $_POST[\'subrice\']; ?>">
<br><label for="total-subs">Subscriptions Sold</label><input id="total-subs" type="text" value="<?php $_POST[\'subname\']; ?>" >
<br><br><div><span class="expenses-label">Expenses</span><span class="expenses-output">$<?php echo $expense; ?></span></div>
<div><span class="net-profit-label">Net Profit</span><span class="net-profit-output">$<?php echo $netprof; ?></span></div>
<br><br><input id="submit" class="button button-primary" type="submit" value="Calculate"></input>
</form>
<?php }
?>
最合适的回答,由SO网友:Omar Tariq 整理而成
add_action( \'wp_dashboard_setup\', \'register_my_dashboard_widget\' );
function register_my_dashboard_widget() {
wp_add_dashboard_widget(
\'net_profit_widget\',
\'Net Profit Calculator\',
\'net_profit_widget_display\'
);
}
function net_profit_widget_display() {
$subPrice = 0;
$subnumb = 0;
if (array_key_exists(\'subprice\', $_POST) !== false) {
$subPrice = $_POST[\'subprice\'];
}
if (array_key_exists(\'subnumb\', $_POST) !== false) {
$subnumb = $_POST[\'subnumb\'];
}
$payperc = "2.9";
$paystan = "0.3";
$netprof = "N/A";
$expense = "N/A";
if ($_SERVER[\'REQUEST_METHOD\'] == \'POST\') {
if ($subPrice === false || $subnumb === false ) {
die("Please fill in all the required information!");
} else {
$expense = $subPrice * (($payperc / 100) + $paystan);
$netprof = ($subPrice - $expense) * $subnumb;
}
}
?>
<div style="color: #777;">Paypal fee per transaction: 2.9% + $0.3</div><br>
<form class="netcalc" method="POST" action="#">
<label for="sub-price">Subscription Price($)</label><input name="subprice" id="sub-price" type="text" value="<?php echo $subPrice; ?>">
<br><label for="total-subs">Subscriptions Sold</label><input name="subnumb" id="total-subs" type="text" value="<?php echo $subnumb; ?>" >
<br><br><div><span class="expenses-label">Expenses</span><span class="expenses-output">$<?php echo $expense; ?></span></div>
<div><span class="net-profit-label">Net Profit</span><span class="net-profit-output">$<?php echo $netprof; ?></span></div>
<br><br><input id="submit" class="button button-primary" type="submit" value="Calculate"></input>
</form>
<?php }