PHP/mySQL - Working with radio buttons?

Associate
Joined
12 Aug 2004
Posts
1,009
Location
Glasgow, Scotland
Hi :)

I'm mucking about with some php here and trying to figure something out, basically i'm trying to replace a form's text input with 2 radio buttons. At the moment I have a field called "MenuItem" in a database which holds either a 1 or nothing. If there is a 1 the link will be included in the menu, and if there is nothing it won't be.

So i'm trying to replace a text input form that currently returns either a 1 or nothing to the user when they are editing a page, when the user edits the page and changes the 1 to nothing in the form it changes in the database ... simple, except thats not really ideal for a user who doesn't understand html etc.

I've tried to replace this with 2 radio buttons to make it easier on the user, so they can just select "Yes" or "No", but as there effectively 2 seperate objects I'm having trouble figuring out how to implement this into the editing form.

I've written the code below which should read from the database and produce the correctly selected radio button upon loading the page, but where I need help is how to let the page know if the user has changed the selected radio button when they've been editing the page?

Code:
if($MenuItem == "1")
{
     Yes <input type="radio" name="MenuItem" value="1" />
     No <input type="radio" name="MenuItem" value="" />
}
else
{
     Yes <input type="radio" name="MenuItem" value="" />
     No <input type="radio" name="MenuItem" value="1" />
}

Thanks :)
 
Back
Top Bottom