You are here: Re: PHP/MySQL and Checkboxes « All PHP « IT news, forums, messages
Re: PHP/MySQL and Checkboxes

Posted by Martin Jay on 05/26/06 21:01

In message <1148664467.157196.151900@y43g2000cwc.googlegroups.com>,
sloane.irwin@gmail.com 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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация