Question involving PHP, MySQL and Forms

Okay, so I'm going to try to explain my problem without a whole lot of lead-up to the problem. Basically what I have is a MySQL function that goes through a table and creates option boxes for each entry in the table:

Code:
function retrieveGames() {
		$gamesList = mysql_query("SELECT * FROM mgsf_games WHERE id > 0 ORDER BY `id` DESC");
		
		while($row = mysql_fetch_array($gamesList)) {
			echo("<input name='gameTitle' type='radio' value='".$row['url']."'> &nbsp;<strong>".$row['name']."</strong><br />");
		}
	}

The end goal is for a list of games to be presented in a form so that a user can select one and the value of the selected option will pass through to another table when they click the Submit button. As I have it right now, the value won't pass. I'm thinking using the option circles won't work, so if anyone has any other ideas I would be very grateful. I was planning on using the "name" attribute as I did with my text fields, but 'options' don't have a name attribute and value doesn't really work.

So yeah, any help would be greatly appreciated. Thanks!

Also, if this is in the wrong forum, I apologise. It could go either Progamming or Web I suppose.
 
Well, there doesn't appear to be anything wrong with the PHP. I wonder if it's a form problem.

One piece of code that I use regularly is this:
PHP:
<?php
if($debug)
{
	?>
  <table cellspacing="0" cellpadding="2">
  <tr>
    <td>Key</td>
    <td>Value</td>
  </tr>
<?php
	while(list($key, $value) = each($_POST))
	{
	?>
  <tr>
    <td><?php echo $key; ?></td>
    <td><?php echo $value; ?></td>
  </tr>
<?php
	}
	reset($_POST);
	?>
</table>
<p>
<?php
}
?>

At the top of the source for the page, I have a simple
PHP:
$debug = true;
that I use to switch on debugging (I bury if($debug) statements all over my code).

But what this does is it dumps out the key/value pairings for everything sent by a form. So you put it in whatever page is receiving your form. This should then give you a "Key" of gameTitle, plus the "Value" of whatever gameTitle has been set to in the form.
 
Ha, wow I'm stupid. Turns out I forgot about a table field I needed input for, so that's why it gave me an error. Thanks for the debug code though, Giles. That's really quite handy and I've got a bunch of debugs scattered in my code too now. :)
 

Latest Posts

Back