MFA Posted February 16, 2013 Share Posted February 16, 2013 my code doesnt seem to work.. the radio buttons appear but nothing beside them .. what i know already: mysql_fetch_row is working - i have tested this using mysqli_num_rows() mysqli_query is working - testing in phpmyadmin and also proven above the problem seems to be with $a ..... $e .. i have tried to echo these variables outside teh form but they dont work. i have also tried to echo them directly ie. $retrieve['question']; and this doesnt work either. could someone please advise what is wrong? cheers ps. i am new at this. this is my code. <?php include 'dbyear2.php'; $qnumber = ($_REQUEST['uqn']); // obtain question number from URL $find = mysqli_query($condbyear2, "SELECT * FROM Renal WHERE UQN='$qnumber'"); while($retrieve=mysqli_fetch_row($find)); { $question = $retrieve['question']; $a = $retrieve['MCQ_A']; $b = $retrieve['MCQ_B']; $c = $retrieve['MCQ_C']; $d = $retrieve['MCQ_D']; $e = $retrieve['MCQ_E']; $answer = $retrieve['answer']; $correct = $retrieve['MCQ_correct']; } ?> <form action='check.php' method='POST'> <table> <tr><td></td><td></td></tr> <tr></tr> <tr><td><input type='radio' name='group1' value='A' /></td><td> <?php echo $a; ?></td></tr> <tr><td><input type='radio' name='group1' value='B' /></td><td> <?php echo $b; ?></td></tr> <tr><td><input type='radio' name='group1' value='C' /></td><td> <?php echo $c; ?></td></tr> <tr><td><input type='radio' name='group1' value='D' /></td><td> <?php echo $d; ?></td></tr> <tr><td><input type='radio' name='group1' value='E' /></td><td> <?php echo $e; ?></td></tr> <tr> <?php // sending the retrieved information from MYSQL via POST for use in check.php file $qnumber; $a; $b; $c; $d; $e; $answer; $correct; ?></tr> <tr><td><input type="submit" value="Submit"></td></tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/274548-php-echo-in-form-is-not-working/ Share on other sites More sharing options...
Psycho Posted February 16, 2013 Share Posted February 16, 2013 Well, one question I have is why are you using a while() loop to get the result from the query? You are apparently only expecting one result so a while loop() is unnecessary and unintuitive. But, your problem is simple. Here is what the manual states about mysqli_fetch_row() Quote Get a result row as an enumerated array In other words it makes the keys of the array 0, 1, 2, etc. I never use fetch_row because of that. Use mysql-_fetch_assoc() instead so the keys of the array are the names of the fields in the query - as you apparently expect them to be. By the way, you could have verified this very easily by doing some simple debugging such as using print_r() or var_dump() on $retrieve Link to comment https://forums.phpfreaks.com/topic/274548-php-echo-in-form-is-not-working/#findComment-1412726 Share on other sites More sharing options...
MFA Posted February 16, 2013 Author Share Posted February 16, 2013 On 2/16/2013 at 12:53 AM, Psycho said: Well, one question I have is why are you using a while() loop to get the result from the query? You are apparently only expecting one result so a while loop() is unnecessary and unintuitive. But, your problem is simple. Here is what the manual states about mysqli_fetch_row() In other words it makes the keys of the array 0, 1, 2, etc. I never use fetch_row because of that. Use mysql-_fetch_assoc() instead so the keys of the array are the names of the fields in the query - as you apparently expect them to be. By the way, you could have verified this very easily by doing some simple debugging such as using print_r() or var_dump() on $retrieve It works now and I understood your explanation. Thank you. I will look into the debugging methods you suggested for next time however like I said I'm very new. Link to comment https://forums.phpfreaks.com/topic/274548-php-echo-in-form-is-not-working/#findComment-1412729 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.