Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Html / PHP form into MySQL DB

Posted by Chris_Isaac (Chris Isaac), 19 March 2004

I've got the following snippet of my script which does what it should, ie, get a multiple select from a drop down list:  

<tr><td>Type</td><td><select name="type[]" multiple>
     <option value="action">Action</option>
     <option value="comedy">Comedy</option>
     <option value="thriller">Thriller</option>
     <option value="horror">Horror</option>
     <option value="childrens">Childrens</option>
     <option value="scifi">Scifi</option>
     <option value="fantacy">Fantasy</option>
     <option value="adult">Adult</option>
     <option value="other">Other</option>

The following bit of PHP then grabs the values concerned:

if(array_key_exists('type', $_GET)) {       $type=join(", ",$_GET['type']);}

Now from that if you were to print $type you get the result you would expect, eg, :

comedy, thriller

in this case 2 options, seperated by comas.

The problem is when I try to inset into a mysql db using the following, it only puts in the fist option:

$query="update dvds set type=\"$type\" where id=$id";

Can you see where I'm going wrong?

PS, the table entry for type is : set ('Action', 'Comedy', etc etc);

Posted by admin (Graham Ellis), 20 March 2004
Can't see it straight off.   Have you tried running the SQL update manually through a mysql client?   I suspect that would give you (and me!) some further clues.

Posted by Chris_Isaac (Chris Isaac), 20 March 2004
Right, I run the following query directly, but had the same results, ie, only 1 entry was accepted:

UPDATE dvds SET type="Action, Comedy" where id=3;

I've also tried variations of the above but can't get it to work, so I guess what I need to know is how to update a SET field ??  I've tried the online manual, but no help, any clues?

Posted by admin (Graham Ellis), 20 March 2004
OK ... the "set" string in space sensitive and I think I spotted a space in front of your Comedy?   Here's an example that works:

mysql> select * from try;
| fred     | id   |
| dick     |    3 |
| tom      |    4 |
| tom      |    5 |
| tom,dick |    6 |
4 rows in set (0.00 sec)

mysql> update try set fred = ("dick,harry") where id = 3;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from try;
| fred       | id   |
| dick,harry |    3 |
| tom        |    4 |
| tom        |    5 |
| tom,dick   |    6 |
4 rows in set (0.00 sec)

Posted by Chris_Isaac (Chris Isaac), 20 March 2004
Thats cured it.

Thanks again.

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho