一旦sql查询成功,就隐藏div

时间:2015-03-01 23:01:31

标签: javascript php html

我正在尝试制作div," yourpick," POST查询成功后隐藏。我知道我在表单中间检查POST,但是我们可以解决这个问题。感谢。

echo '<div class="yourpick" style="display:block;">
            YOUR PICK:<br><form method="post" action="draft.php">';
    echo '<input type="radio" name="pick" value="user1">User1<br>';

if(isset($_POST["pick"])){
$pick = $_POST["pick"];
$picksql = "UPDATE picks SET playerpick='" . $pick . "' WHERE id=$id AND picknum=$picknum";

if ($mysqli->query($picksql) === TRUE) {
echo "Pick Successful!";
echo "<script>document.getElementById('yourpick').style.display = 'none';</script>";
} else {
echo "Error Ocurred. Please contact commisioner.";
}
}


echo "<input type='submit' name='submit' /></form></div>";

2 个答案:

答案 0 :(得分:0)

您不需要Javascript:

if (isset($_POST["pick"])) {
  $pick    = $_POST["pick"];
  $picksql = "UPDATE picks 
              SET playerpick = '$pick' 
              WHERE id = $id AND picknum = $picknum";
  if ($mysqli->query($picksql) === TRUE) { 
    echo "Pick Successful!";
  } else {
    echo "Error Ocurred. Please contact commisioner.";
  }
}
else {
  echo '<div class="yourpick" style="display:block;">'.
       'YOUR PICK:<br><form method="post" action="draft.php">'.
       '<input type="radio" name="pick" value="user1">User1<br>'.
       '<input type="submit" name="submit"></form></div>';
}

很抱歉,但我并未指出此代码存在明显的安全风险。

答案 1 :(得分:0)

最好在HTML中使用php替代语法,所以如果isset($_POST["pick"]),则隐藏div:

<?php if(isset($_POST["pick"])): ?>
    <div class="yourpick" style="display:block;">
    YOUR PICK:<br><form method="post" action="draft.php">
    <input type="radio" name="pick" value="user1">User1<br>
    <input type="submit" name="submit"></form></div>
<?php endif; ?>

使您的代码变得干净整洁。 :)