Re: PHP/MySQL and Checkboxes
- From: Martin Jay <martin@xxxxxxxxxxxxxxxx>
- Date: Fri, 26 May 2006 19:01:48 +0100
In message <1148664467.157196.151900@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, sloane.irwin@xxxxxxxxx writes
I've created an entry form for my database and it includes four
checkboxes. I am also making an 'edit page', where I wan't to use the
same form as the entry form so that users can click the edit link from
the main display table, change all or just a few values, and it will
then change that row in the db.
With the entry form I get an Undefined Index notice when the checkboxes
are not checked, but no errors if they are checked. Why would this be?
This is probably because when the checkboxes aren't ticked their name isn't sent by the form, so effectively $_REQUEST['drive1'] (for example) doesn't exist.
You could get around this by changing:
$query = $query . '"' . $_REQUEST['drive1'] . '", ';
to:
$query = $query . '"' . (isset($_REQUEST['drive1'])) ? $_REQUEST['drive1'] : ""; . '", ';
Beware wrapping: should all be on one line.
So, if $_REQUEST['drive1'] has a value it will be added to the string, otherwise "" (nothing) will be added.
As for the view/edit page, How do I make it so the checkboxes will
appear checked or unchecked whether or not the specific feature is
present on that line of the db?
In the HTML you would add 'checked' to the <input>, for example:
<input type="checkbox" name="drive1" value="yes" checked>
In this example the checkbox would be ticked on the page in a web browser.
--
Martin Jay
Phone/SMS: +44 7740 191877
Fax: +44 870 915 2124
.
- Follow-Ups:
- Re: PHP/MySQL and Checkboxes
- From: sloane . irwin
- Re: PHP/MySQL and Checkboxes
- References:
- PHP/MySQL and Checkboxes
- From: sloane . irwin
- PHP/MySQL and Checkboxes
- Prev by Date: PHP/MySQL and Checkboxes
- Next by Date: Re: PHP/MySQL and Checkboxes
- Previous by thread: PHP/MySQL and Checkboxes
- Next by thread: Re: PHP/MySQL and Checkboxes
- Index(es):
Relevant Pages
|