Re: PHP/MySQL and Checkboxes



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
.



Relevant Pages

  • PHP/MySQL and Checkboxes
    ... I've created an entry form for my database and it includes four ... I am also making an 'edit page', where I wan't to use the ... With the entry form I get an Undefined Index notice when the checkboxes ...
    (alt.php)
  • Re: A form to be filled in and then to be used for a query
    ... checkboxes); and a third table for answers, with links to the other two ... I want to use an entry form for specifying my query. ... form bound to a query on your table. ...
    (microsoft.public.access.forms)
  • Re: Editing document
    ... the template so the only way to edit them is to use the form. ... clear boxes. ... Supposing you are still working on the document with the checkboxes, ... between the checkedbox and unchecked box in regular text so I used format ...
    (microsoft.public.word.vba.general)
  • RE: Trouble with editing data from a user form
    ... "ryssa>" wrote: ... > I currently have an entry form which works with a save button to enter ... > 'Move selection back to beginning of worksheet for a new entry ... > the user to edit that record. ...
    (microsoft.public.excel.programming)
  • Trouble with editing data from a user form
    ... I currently have an entry form which works with a save button to enter ... 'Select workbook & move selection to cell A1 ... 'Move selection back to beginning of worksheet for a new entry ... I have an edit button on the worksheet which opens a form to ask the ...
    (microsoft.public.excel.programming)