【发布时间】:2018-07-23 02:04:48
【问题描述】:
我正在制定一个“健康计划”,您每天做的每件“健康”事情都会获得 1 分,例如,如果您有 30 分钟的锻炼,您就会获得 1 分。它的工作原理如下图所示:
<form method="post">
<label>Did you have 30 minutes of exercise today? (+1)</label>
<select name="question">
<option value="yes">Yes</option>
<option value="no">No</option>
</select> <input type="submit" class="btn btn-outline-light" name="form1">
</form>
<form method="post">
<label>Have you drinken 8 glasses of water today? (+1)</label>
<select name="question">
<option value="yes">Yes</option>
<option value="no">No</option>
</select> <input type="submit" class="btn btn-outline-light" name="form2">
</form>
<form method="post">
<label>Did you use your phone for more than two hours today? (-1)</label>
<select name="question">
<option value="yes">Yes</option>
<option value="no">No</option>
</select> <input type="submit" class="btn btn-outline-light" name="form3">
</form>
<?php
/* Then using PHP I want to have each form submitted, add or remove 1 from an overall score, something like this: */
$score = 0;
if (isset($_POST['form1'])) {
$question = $_POST['question'];
if ($question = "yes") {
// +1 point
$score = +1;
}
}
if (isset($_POST['form2'])) {
$question = $_POST['question'];
if ($question = "yes") {
// +1 point
$score = +1;
}
}
if (isset($_POST['form3'])) {
if ($question = "yes") {
// -1 point
$score = +1;
}
} ?>
然后我想要 $score 中的 +1 或 -1。我不确定如何使用 PHP 实际添加点。我希望 $score 在 if 语句之外更新,否则,对于每个 if 语句,它将添加一个并且 $score 仍然是 = 到 1
谢谢!
雅各布
【问题讨论】:
-
您能否详细说明您希望发生的事情——例如,当您单击“提交”按钮时,应该发生什么?
-
我想让 $score 在每次累积数字时添加或删除 1,以便与其他用户进行比较。
-
顺便说一句,变量不会永远存储值,一旦脚本执行完值就消失了,你需要使用数据库。
-
每次脚本执行时,您都需要一些东西来存储变量。否则,您只会在页面重新加载后丢失变量。
标签: php html numbers add points