我知道标题没有多说。
我正在创建一个网站,如果他们愿意,我希望人们查看一本书。 此代码位于页面上的产品信息下:
<span class='starRating'>
<input id="rating5" type="radio" name="rating" value="5">
<label for="rating5">5</label>
<input id="rating4" type="radio" name="rating" value="4">
<label for="rating4">4</label>
<input id="rating3" type="radio" name="rating" value="3" checked>
<label for="rating3">3</label>
<input id="rating2" type="radio" name="rating" value="2">
<label for="rating2">2</label>
<input id="rating1" type="radio" name="rating" value="1">
<label for="rating1">1</label>
</span>
</select><br><br>
<button type='submit' onclick='comment.php'>Voeg toe</button>
<?php
$name = $_GET['Naam'];
$comment = $_GET['Comment'];
$rating = $_GET['rating'];
if ($name != '' && $comment != '') {
switch ($rating1) {
case $rating = "1" :
$ratingImg = '<img src=/nl/images1/star-on.svg>';
break;
case $rating = "2" :
$ratingImg = '<img src=/nl/images1/star-on.svg><img src=/nl/images1/star-on.svg>';
break;
case $rating = "3" :
$ratingImg = '<img src=/nl/images1/star-on.svg><img src=/nl/images1/star-on.svg><img src=/nl/images1/star-on.svg>';
break;
case $rating = "4" :
$rating = '<img src=/nl/images1/star-on.svg><img src=/nl/images1/star-on.svg><img src=/nl/images1/star-on.svg><img src=/nl/images1/star-on.svg>';
break;
case $rating = "5" :
$ratingImg = '<img src=/nl/images1/star-on.svg><img src=/nl/images1/star-on.svg><img src=/nl/images1/star-on.svg><img src=/nl/images1/star-on.svg><img src=/nl/images1/star-on.svg>';
break;
}
$finalComment = "<?php
echo '<hr><p>Door: $name</p><p>Score: $ratingImg</p><p>$comment</p><br>';?>"
;
我想将人们选择的星数作为变量。我有来自here的星系。当我发送以下内容时,在我的URL栏中:...?rating = 5&amp; ...
我可以在$ratingImg
变量中获取此内容吗?如果我的问题不清楚,请说出来。
答案 0 :(得分:0)
$name = $_GET['Naam'];
$comment = $_GET['Comment'];
$rating = $_GET['rating'];
if ($name != '' && $comment != '') {
switch ($rating1) {
更改为
$name = $_GET['Naam'];
$comment = $_GET['Comment'];
$rating = $_GET['rating'];
if ($name != '' && $comment != '') {
switch ($rating) {
您没有变量 $ rating1
答案 1 :(得分:0)
您的开关正在调用名为$ rating1的变量,该变量未定义。它应该改为$ rating
错别选Typos是杀手。 =(