我需要一些帮助。我有一个带有多个单选按钮和一个输入类型按钮的表单(当点击时打开一个模态框,然后你最后点击输入类型提交)问题是我无法显示单选按钮选择的值模式框如:你确定要投票和选择价值' ?如果是,那就投票吧! 这是我的PHP代码。我还使用javascript for Google Material Design Lite模式框。
<?php
$pollid = $_GET ['pollid'];
echo $_POST['polloption'];
$connect = mysqli_connect('localhost', 'root', '', 'poll');
$query = "SELECT * FROM polls where pollid='poll1'";
$q = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($q)) {
$id = $row[0];
$title = $row[1];
$pollid = $row[2];
$ipadress = $row[3];
?>
<table>
<form action="" method="POST">
<tr>
<td>
<?php
$questions = "SELECT * FROM questions where pollid='$pollid'";
$q2 = mysqli_query($connect, $questions);
while($r = mysqli_fetch_array($q2)) {
$question = $r[1];
$votes = $r[2];
$newvotes = $votes + 1;
$ip = $_SERVER['REMOTE_ADDR'];
$newipadress = $ipadress."$ip,";
if (isset($_POST['vote'])) {
$polloption = $_POST['polloption'];
if ($polloption == "") {
die("You didnt select an option.");
} else {
$ipadresse = explode(",", $ipadress);
if (in_array($ip, $ipadresse)) {
die("You've already voted");
} else {
mysqli_query($connect, "UPDATE questions SET votes = '$newvotes' WHERE pollid='$pollid' AND question = '$polloption'");
mysqli_query($connect, "UPDATE polls set ipadress='$newipadress' where pollid='$pollid' ");
die("You voted succesfully!");
}
}
}
echo '<tr><td>'.$question.'</td><td><input type="radio" name="polloption" value="'.$question.'"/> '.$votes.' votes</td></tr>';
}
}
?>
<tr><td>
<input id="show-dialog" type="button" name="vote" value="Vote" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" checked />
</td></tr>
<dialog id="dialog" class="mdl-dialog">
<h3 class="mdl-dialog__title">Are you sure want to vote <?php echo $polloption; ?> ?</h3>
<div class="mdl-dialog__content">
<p> <?php echo $polloption;?>
</p>
</div>
<div class="mdl-dialog__actions">
<input type="submit" name="vote" value="Vote" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" checked />
<button type="button" class="mdl-button">Close</button>
</div>
</dialog>
<script>
var dialog = document.querySelector('dialog');
var showDialogButton = document.querySelector('#show-dialog');
if (! dialog.showModal) {
dialogPolyfill.registerDialog(dialog);
}
showDialogButton.addEventListener('click', function() {
dialog.showModal();
});
dialog.querySelector('button:not([disabled])').addEventListener('click', function() {
dialog.close();
});
</script>
</td>
</tr>
</form>
</table>