Jump to content

php echo in form is not working


MFA

Recommended Posts

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
Share on other sites

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()

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.