I am using PHP 4.0 and MySQL to do sort of a guest book application. I want to enable people to submit their answer to a specific question. There's more to it than the following, but here's the simplified problem.
The fields I'm requiring are:
- first_name
- last_name
- other (eg., how would you describe yourself)
- answer
I want to allow people to remain anonymous if they so choose. So I've included a radio button in my form where they can select to be anonymous (value="yes") or not (value="no").
If they choose to remain anonymous, I want to display only the "other" field and the "answer" field.
If they choose not to remain anonymous, I want to display all 4 fields.
I have tried every combination of the "if" conditional imaginable and I can't get this to work. Here's what I'm thinking SHOULD work. Any help with this is unfathomably appreciated!
<?php
--- connect to database ---
$result = mysql_query("SELECT * FROM table_name", $db);
while ($myrow = mysql_fetch_array($result)) {
if ($anonymous == no) {
printf ("%s %s<br>\n", $myrow["first_name"], $myrow["last_name"]);
}
printf ("%s\n", $myrow["other"]);
printf ("<p>%s</p>\n", $myrow["answer"]);
}
?>