Get ready for BLACK FRIDAY shopping starting in

Forums

This topic is locked

DWMX | PHP | MYSQL trouble with list box

Posted 06 Apr 2005 23:49:27
1
has voted
06 Apr 2005 23:49:27 Dan Bell posted:
MY trouble is that I am using Dreamweaver to handle all of the details related to Inserting, updating, and other tasks with PHP and MySQL. I have had pretty good success but have run into a problem that I cannot solve.

Background:
Database has 4 records id, Q1, Q2, and Q3 where Q* is the result of a question. All of the fields are text except for the id and it is int. I can get the data into these records using text, radiogroups menus but not list boxes where more than one option is selected. In Dreamweaver I have selected the multiple option and have used both the mysql and ADODB Server methods. The database will only capture one record. I tried changing the data type to ENUM and SET but still could only get one value into the database.

Question: It seems to me that the data must be configured into an array but Dreamweaver does not mention this at all. I have searched every place I could think of and could not fing an answer.

Please Help

DB

Replies

Replied 07 Apr 2005 01:43:08
07 Apr 2005 01:43:08 Chris Charlton replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>Database has 4 records id, Q1, Q2, and Q3 where Q* is the result of a question. All of the fields are text except for the id and it is int. I can get the data into these records using text, radiogroups menus but not list boxes where more than one option is selected. In Dreamweaver I have selected the multiple option and have used both the mysql and ADODB Server methods. The database will only capture one record. I tried changing the data type to ENUM and SET but still could only get one value into the database.<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Yup, you've ventured into the handcoding arena. DW MX/MX2004 don't have good support for handling ENUM/SET. Infact, the low-down is dropdowns/radiobuttons would use a ENUM (single), and lists/checkbox groups would use SET (multiple).

~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>
Replied 07 Apr 2005 18:44:11
07 Apr 2005 18:44:11 Dan Bell replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>Database has 4 records id, Q1, Q2, and Q3 where Q* is the result of a question. All of the fields are text except for the id and it is int. I can get the data into these records using text, radiogroups menus but not list boxes where more than one option is selected. In Dreamweaver I have selected the multiple option and have used both the mysql and ADODB Server methods. The database will only capture one record. I tried changing the data type to ENUM and SET but still could only get one value into the database.<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Yup, you've ventured into the handcoding arena. DW MX/MX2004 don't have good support for handling ENUM/SET. Infact, the low-down is dropdowns/radiobuttons would use a ENUM (single), and lists/checkbox groups would use SET (multiple).<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Thank you for your help. I am a bit new at this process of hand coding. What do I need to edit to make it work? Here is a copy of my code:

<pre id=code><font face=courier size=2 id=code>&lt;?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "" ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "" ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "" ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "" ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "" ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1") {
$insertSQL = sprintf("INSERT INTO users_usr (question_01, question_02) VALUES (%s, %s)",
GetSQLValueString($HTTP_POST_VARS['RadioGroup1'], "text",
GetSQLValueString($HTTP_POST_VARS['select'], "text");

mysql_select_db($database_hermes, $hermes);
$Result1 = mysql_query($insertSQL, $hermes) or die(mysql_error());

$insertGoTo = "list.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;list&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form action="&lt;?php echo $editFormAction; ?&gt;" name="form1" method="POST"&gt;
1
&lt;p&gt;
&lt;label&gt;
&lt;input type="radio" name="RadioGroup1" value="true"&gt;
true&lt;/label&gt;
&lt;br&gt;
&lt;label&gt;
&lt;input type="radio" name="RadioGroup1" value="false"&gt;
false&lt;/label&gt;
&lt;/p&gt;
&lt;p&gt;2&lt;/p&gt;
&lt;p&gt;
&lt;select name="select" size="4" multiple&gt;
&lt;option value="spiral"&gt;spiral&lt;/option&gt;
&lt;option value="cocci"&gt;cocci&lt;/option&gt;
&lt;option value="bacillus"&gt;bacillus&lt;/option&gt;
&lt;option value="unicellular"&gt;unicellular&lt;/option&gt;
&lt;/select&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;input type="submit" name="Submit" value="submit"&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;input type="hidden" name="MM_insert" value="form1"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</font id=code></pre id=code>

Edited by - dmbe11 on 07 Apr 2005 18:46:36
Replied 07 Apr 2005 21:15:20
07 Apr 2005 21:15:20 Chris Charlton replied:
Offhand your SQL (INSERT) code looks correct.

Your database, is the <i>columntype</i> set to ENUM? If so, what are the values? Most common are ENUM('Y','N'), is yours ENUM('true','false') or ENUM ('1','0')? Like I said, the PHP/SQL code looks correct, let's now look at your DB.

~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>
Replied 07 Apr 2005 22:34:34
07 Apr 2005 22:34:34 Dan Bell replied:
My database is working fine for the radiogroup for question 1. The problem is with question 2. the database type is:

set('spiral',cocci','bacillus','unicellular')

The data is comming from question 2 in the form as a list box multiple

Thank you for your help,

Dan

Edited by - dmbe11 on 08 Apr 2005 02:12:31

Reply to this topic