php - Comparing a value inside database with input value -
my if statement doesn't recognize textbox name ("ans"). should change? , should put it? want know if if statement correct; want compare value inside database input value ("ans"). in advance.
<?php $con = mysql_connect("localhost", "root", "avtt123"); mysql_select_db("arvintarrega",$con); $sql = "select * identification"; $mydata = mysql_query($sql,$con); echo '<form method = "post">'; while($iden = mysql_fetch_array($mydata)) { echo '<center>' . $iden['question_number'] . '. ' . $iden['statement'] . ' <input type = "text" name = "ans"></input></center></br>'; if($iden['correct_answer'] == $_request['ans']) { echo "correct"; } else { echo "wrong"; } } echo '</form>'; ?> <form method = "post"> <input type = "submit" name = "submit" value = "submit" class="btn btn-warning"> </form>
give following try worked me, , i'm using mysqli_
connection , query, change xxx
own credentials.
<?php $db_host = 'xxx'; $db_user = 'xxx'; $db_pass = 'xxx'; $db_name = 'xxx'; $link = new mysqli($db_host, $db_user, $db_pass, $db_name); if($link->connect_errno > 0) { die('connection failed [' . $link->connect_error . ']'); } $sql = "select * identification limit 1"; $mydata = mysqli_query($link, $sql); echo '<form method = "post">'; while($iden = mysqli_fetch_array($mydata)) { echo '<center>' . $iden['question_number'] . '. ' . $iden['statement'] . ' <input type = "text" name = "ans"></center><br/>'; if(isset($_post['submit'])) { if(isset($_post['ans']) && $iden['correct_answer'] == $_post['ans']){ echo "correct<br><br>"; } else { echo "wrong<br><br>"; } } // if(isset($_post['submit'])) end brace } // while loop end brace echo '<input type = "submit" name = "submit" value = "submit" class="btn btn-warning">'; echo '</form>'; ?>
Comments
Post a Comment