27bd Html / PHP form into MySQL DB - Writing PHP
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
Html / PHP form into MySQL DB

Posted by Chris_Isaac (Chris Isaac), 19 March 2004
Hi

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

Code:
<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>
</select></td></tr>



The following bit of PHP then grabs the values concerned:

Code:
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, :

Quote:
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:

Code:
$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:

Code:
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:

Code:
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 www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.
9342

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2013: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho
0