html - Dice rolling program in PHP -
i made simple program user has guess value rolled virtual dice.
here's html , php:
<body> <h2 id="heading"> we're gonna roll dice! <br><small>and have guess number dice roll.</small></h2> <form action="" method="post"> <div id="test-container"> <p>select guess: </p> <select class="form-control" id="select" name="dice"> <option value="">select...</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select> </div> <button id="submit" type="submit" type="button" name="roll" class="btn btn-primary">roll!</button> <?php if(isset($_post['roll'])) { $dice = $_post['dice']; $rand = rand(1,6); if($dice == $rand) { echo "<br>" . "your guess correct! number rolled dice " . $rand . "!"; } else{ echo "<br>" . "your guess wrong! number rolled dice " . $rand . " number entered " . $dice . "!"; } } ?> </form> </body> </html>
the code works, that's not issue. when press submit, want following gif (positioned in-between button , echoed output) appear, , play once without looping:
i've tried many ways this, none of them seem work!
i understand require image editor prevent looping forever. displaying it, syntax echo "<img src='handroll.gif'>"
, found out.
have tried setting value of $_post[roll] null after rolling dice. see it, the value remains true once button clicked , not "re-initializing" per se.
if(isset($_post['roll'])) { // need // last line or $_post['roll'] = null; }
because, when submit form, form data or submit status gets reset , session value.
if above doesn't work, can try form/input type=submit setup. it's easier drive button clicks through jquery/js.
Comments
Post a Comment