Forums
This topic is locked
list/menu Insert Record form question?
Posted 11 Feb 2005 01:10:46
1
has voted
11 Feb 2005 01:10:46 Bobby Edgar posted:
Is it possible to have a list/menu giving people the option to select several things, and put those selected options into one database field? I need to allow my users to list the types of jobs they wish to have mailed to them. They need to be able to select more than one option, and then the script will take the information passed by a new job posting, search that field for users who have choosen to get jobs such at the one just posted, and mail it to them. Make Sense?I recently switched to PHP/MYSQL and this used to work fine when I used ASP/Access.
Here is my code:
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<font color="#666666" size="3">
<select name="Type" size="6" multiple>
<option selected>Choose One</option>
<option>Administrative</option>
<option>Designer</option>
<option>Technician</option>
<option>Director</option>
<option>Choreographers</option>
<option>Management</option>
<option>Musician</option>
<option>Internship</option>
<option>Office Staff</option>
<option>Writers Wanted</option>
<option>Volunteers</option>
<option>Educational</option>
<option>Large/Multiple Calls</option>
<option>Other / Misc.</option>
</select>
<input type="submit" name="Submit" value="Submit">
</font>
<input type="hidden" name="MM_insert" value="form1">
</form>
When I do this, it only places the last choosen one in the field. It must be possible, and I have scoured the web for two days looking for the answer.
Bobby
DMX2004 / XP-Sp2 / PHP/MYSQL<font color=blue></font id=blue>
Replies
Replied 11 Feb 2005 01:25:47
11 Feb 2005 01:25:47 Vince Baker replied:
problem is that you actually need to store these items in an array and then turn them into a comma seperated list.....
I will write you a bit of code tomorrow first thing.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
I will write you a bit of code tomorrow first thing.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
Replied 11 Feb 2005 01:34:07
11 Feb 2005 01:34:07 Bobby Edgar replied:
Thank you so much. I appreciate the quick response. THANKS DMXZONE!!!
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
problem is that you actually need to store these items in an array and then turn them into a comma seperated list.....
I will write you a bit of code tomorrow first thing.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
problem is that you actually need to store these items in an array and then turn them into a comma seperated list.....
I will write you a bit of code tomorrow first thing.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 11 Feb 2005 02:12:10
11 Feb 2005 02:12:10 Chris Charlton replied:
<b>MySQL datatype SET</b> would be the choice to save comma-seperated values in one column (field), and as for HTML output a multiselect list/menu is prime for that.
Hope that helps. <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
<b>Further detail:</b> you can send MySQL the string value or even a #, because internally MySQL stores an array for the SET values. <b>Example:</b> SET ('apples','oranges','plums')... you can INSERT/UPDATE and send 'apple,plums' or 0,2 as MySQL registers them the same. I would read more on MySQLs' site as they explain better - www.mysql.com .
~ ~ ~ ~ ~ ~ ~
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>
Edited by - ccharlton on 11 Feb 2005 02:16:16
Hope that helps. <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
<b>Further detail:</b> you can send MySQL the string value or even a #, because internally MySQL stores an array for the SET values. <b>Example:</b> SET ('apples','oranges','plums')... you can INSERT/UPDATE and send 'apple,plums' or 0,2 as MySQL registers them the same. I would read more on MySQLs' site as they explain better - www.mysql.com .
~ ~ ~ ~ ~ ~ ~
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>
Edited by - ccharlton on 11 Feb 2005 02:16:16
Replied 11 Feb 2005 03:04:10
11 Feb 2005 03:04:10 Bobby Edgar replied:
I have done as you said:
MySql Field Setup
Type= set('Administrative','Designer','Technician','Director','Choreographer','Management','Musician','Internship','Office Staff','Writers Wanted','Volunteers','Educational','Large/Multiple Calls','Other / Misc.')
Html Form Code:
<select name="Type" size="6" multiple class="forms" id="Type">
<option>Administrative</option>
<option>Designer</option>
<option>Technician</option>
<option>Director</option>
<option>Choreographers</option>
<option>Management</option>
<option>Musician</option>
<option>Internship</option>
<option>Office Staff</option>
<option>Writers Wanted</option>
<option>Volunteers</option>
<option>Educational</option>
<option>Large/Multiple Calls</option>
<option>Other / Misc.</option>
</select>
It still only posts the last choice selected from the list/menu. I referenced the mysql site as you suggested, and believe I am following instructions.
I really apprecaite the help, as this has been driving me crazy for days now..
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
<b>MySQL datatype SET</b> would be the choice to save comma-seperated values in one column (field), and as for HTML output a multiselect list/menu is prime for that.
Hope that helps. <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
<b>Further detail:</b> you can send MySQL the string value or even a #, because internally MySQL stores an array for the SET values. <b>Example:</b> SET ('apples','oranges','plums')... you can INSERT/UPDATE and send 'apple,plums' or 0,2 as MySQL registers them the same. I would read more on MySQLs' site as they explain better - www.mysql.com .
~ ~ ~ ~ ~ ~ ~
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>
Edited by - ccharlton on 11 Feb 2005 02:16:16
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
MySql Field Setup
Type= set('Administrative','Designer','Technician','Director','Choreographer','Management','Musician','Internship','Office Staff','Writers Wanted','Volunteers','Educational','Large/Multiple Calls','Other / Misc.')
Html Form Code:
<select name="Type" size="6" multiple class="forms" id="Type">
<option>Administrative</option>
<option>Designer</option>
<option>Technician</option>
<option>Director</option>
<option>Choreographers</option>
<option>Management</option>
<option>Musician</option>
<option>Internship</option>
<option>Office Staff</option>
<option>Writers Wanted</option>
<option>Volunteers</option>
<option>Educational</option>
<option>Large/Multiple Calls</option>
<option>Other / Misc.</option>
</select>
It still only posts the last choice selected from the list/menu. I referenced the mysql site as you suggested, and believe I am following instructions.
I really apprecaite the help, as this has been driving me crazy for days now..
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
<b>MySQL datatype SET</b> would be the choice to save comma-seperated values in one column (field), and as for HTML output a multiselect list/menu is prime for that.
Hope that helps. <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
<b>Further detail:</b> you can send MySQL the string value or even a #, because internally MySQL stores an array for the SET values. <b>Example:</b> SET ('apples','oranges','plums')... you can INSERT/UPDATE and send 'apple,plums' or 0,2 as MySQL registers them the same. I would read more on MySQLs' site as they explain better - www.mysql.com .
~ ~ ~ ~ ~ ~ ~
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>
Edited by - ccharlton on 11 Feb 2005 02:16:16
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 11 Feb 2005 04:53:57
11 Feb 2005 04:53:57 Bobby Edgar replied:
I have been researching some more, and yes it appears that it must be put into an array. I have done that much, but have no clue how to then out that array into the database. Your help will save my brain!!! You can view my page at this URL: theatreresourcegroup.org/staffing_main_jobs_direct_register_checkboxes.php
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
problem is that you actually need to store these items in an array and then turn them into a comma seperated list.....
I will write you a bit of code tomorrow first thing.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
problem is that you actually need to store these items in an array and then turn them into a comma seperated list.....
I will write you a bit of code tomorrow first thing.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 11 Feb 2005 17:58:31
11 Feb 2005 17:58:31 Bobby Edgar replied:
Here is the code generated when the form is submitted. It creates the array from the list/menu, but I have no idea how to place the array results into the table...
Array
(
[FirstName] => Robert
[LastName] => Edgar
[EmailAddress] => ????
[user_ip] => ????
[direct_id] => 389265493
[UserID] => ????
[JobType] => Array
(
[0] => Administrative
[1] => Technician
[2] => Choreographers
[3] => Musician
[4] => Internship
[5] => Writers Wanted
[6] => Educational
)
[Submit2] => Sign Me Up
[MM_insert] => jobs_direct
)
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
problem is that you actually need to store these items in an array and then turn them into a comma seperated list.....
I will write you a bit of code tomorrow first thing.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Array
(
[FirstName] => Robert
[LastName] => Edgar
[EmailAddress] => ????
[user_ip] => ????
[direct_id] => 389265493
[UserID] => ????
[JobType] => Array
(
[0] => Administrative
[1] => Technician
[2] => Choreographers
[3] => Musician
[4] => Internship
[5] => Writers Wanted
[6] => Educational
)
[Submit2] => Sign Me Up
[MM_insert] => jobs_direct
)
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
problem is that you actually need to store these items in an array and then turn them into a comma seperated list.....
I will write you a bit of code tomorrow first thing.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 12 Feb 2005 19:05:35
12 Feb 2005 19:05:35 Bobby Edgar replied:
Can anyone help me with this? I didn't get the code as I was told I would. I am really stuck with my site creation until I can get this figured out...
Replied 11 Aug 2006 11:33:44
11 Aug 2006 11:33:44 Julian Hockings replied:
This is a very late reply, but may be helpful to someone in the future. Basically, you can't really use DW's built-in behaviors to take a multiple select list and perform an insert record. You can, but only the last selection in the list will be inserted. In order to get all the multiple selections inserted into the database, you have to do some hand-coding.
First, you need to rename your form's select tag from name="Type" to name="Type[]". Putting those brackets in at the end of the name will make it so that when PHP receives the form contents it will turn them into an array. Then you have to take DW's usual insert record code and put it within a loop that loops through each of the array items. Here's an example:
// set it up
reset ($Type); // this sets the array pointer to the beginning of the array
mysql_select_db($database, $db);
// loop through array of Type[] and write each instance to db
while (list($key, $val) = each ($Type)) {
$insertSQL = sprintf("INSERT INTO yourtable (yourfield) VALUES (%s)",
GetSQLValueString($val, "text");
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
} // end loop
Note that you also need to have the GetSQLValueString function on the page somewhere. DW automatically inserts this function whenever you do an insert record behavior. You can copy and paste it from another page if you like. Also be sure to have the include file to your connection settings somewhere on the page.
First, you need to rename your form's select tag from name="Type" to name="Type[]". Putting those brackets in at the end of the name will make it so that when PHP receives the form contents it will turn them into an array. Then you have to take DW's usual insert record code and put it within a loop that loops through each of the array items. Here's an example:
// set it up
reset ($Type); // this sets the array pointer to the beginning of the array
mysql_select_db($database, $db);
// loop through array of Type[] and write each instance to db
while (list($key, $val) = each ($Type)) {
$insertSQL = sprintf("INSERT INTO yourtable (yourfield) VALUES (%s)",
GetSQLValueString($val, "text");
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
} // end loop
Note that you also need to have the GetSQLValueString function on the page somewhere. DW automatically inserts this function whenever you do an insert record behavior. You can copy and paste it from another page if you like. Also be sure to have the include file to your connection settings somewhere on the page.
Replied 04 Sep 2006 08:23:54
04 Sep 2006 08:23:54 Brian Mr. replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
This is a very late reply, but may be helpful to someone in the future. Basically, you can't really use DW's built-in behaviors to take a multiple select list and perform an insert record. You can, but only the last selection in the list will be inserted. In order to get all the multiple selections inserted into the database, you have to do some hand-coding.
First, you need to rename your form's select tag from name="Type" to name="Type[]". Putting those brackets in at the end of the name will make it so that when PHP receives the form contents it will turn them into an array. Then you have to take DW's usual insert record code and put it within a loop that loops through each of the array items. Here's an example:
// set it up
reset ($Type); // this sets the array pointer to the beginning of the array
mysql_select_db($database, $db);
// loop through array of Type[] and write each instance to db
while (list($key, $val) = each ($Type)) {
$insertSQL = sprintf("INSERT INTO yourtable (yourfield) VALUES (%s)",
GetSQLValueString($val, "text");
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
} // end loop
Note that you also need to have the GetSQLValueString function on the page somewhere. DW automatically inserts this function whenever you do an insert record behavior. You can copy and paste it from another page if you like. Also be sure to have the include file to your connection settings somewhere on the page.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
What value would I place in the "$key" ?
thx
This is a very late reply, but may be helpful to someone in the future. Basically, you can't really use DW's built-in behaviors to take a multiple select list and perform an insert record. You can, but only the last selection in the list will be inserted. In order to get all the multiple selections inserted into the database, you have to do some hand-coding.
First, you need to rename your form's select tag from name="Type" to name="Type[]". Putting those brackets in at the end of the name will make it so that when PHP receives the form contents it will turn them into an array. Then you have to take DW's usual insert record code and put it within a loop that loops through each of the array items. Here's an example:
// set it up
reset ($Type); // this sets the array pointer to the beginning of the array
mysql_select_db($database, $db);
// loop through array of Type[] and write each instance to db
while (list($key, $val) = each ($Type)) {
$insertSQL = sprintf("INSERT INTO yourtable (yourfield) VALUES (%s)",
GetSQLValueString($val, "text");
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
} // end loop
Note that you also need to have the GetSQLValueString function on the page somewhere. DW automatically inserts this function whenever you do an insert record behavior. You can copy and paste it from another page if you like. Also be sure to have the include file to your connection settings somewhere on the page.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
What value would I place in the "$key" ?
thx
Replied 26 Sep 2006 18:58:51
26 Sep 2006 18:58:51 Afonso Marques replied:
Thanks! Thanks! Thanks! Thanks!
I was starting to melt down with this issue.
After tons of articles, websites, forum searches and few thousands of other things, finally the answer!
It works, and my problem is solved!
PS: Why doesn't Adobe simplify this stuff on the next update or version of DW? Just a thought...
I was starting to melt down with this issue.
After tons of articles, websites, forum searches and few thousands of other things, finally the answer!
It works, and my problem is solved!
PS: Why doesn't Adobe simplify this stuff on the next update or version of DW? Just a thought...
Replied 30 Dec 2006 08:36:37
30 Dec 2006 08:36:37 Tim Lehmann replied:
Hello,
i have the same Problem,
where must i insert the code in my Site,
here is the Code of my Recordset:
Thanks for Helping.
Best Regards
Tim
<?php require_once('Connections/local.php'); ?>
<?php
// Load the common classes
require_once('includes/common/KT_common.php');
// Load the tNG classes
require_once('includes/tng/tNG.inc.php');
// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher(""
// Make unified connection variable
$conn_local = new KT_connection($local, $database_local);
// Start trigger
$formValidation = new tNG_FormValidation();
$tNGs->prepareValidation($formValidation);
// End trigger
if (!function_exists("GetSQLValueString") {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string" ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
mysql_select_db($database_local, $local);
$query_languages = "SELECT * FROM sbdtng_languages ORDER BY sbdtng_languages.sb_desc";
$languages = mysql_query($query_languages, $local) or die(mysql_error());
$row_languages = mysql_fetch_assoc($languages);
$totalRows_languages = mysql_num_rows($languages);
mysql_select_db($database_local, $local);
$query_currencies = "SELECT * FROM sbdtng_currencies_all ORDER BY sbdtng_currencies_all.sb_desc";
$currencies = mysql_query($query_currencies, $local) or die(mysql_error());
$row_currencies = mysql_fetch_assoc($currencies);
$totalRows_currencies = mysql_num_rows($currencies);
// Make an insert transaction instance
$ins_users = new tNG_insert($conn_local);
$tNGs->addTransaction($ins_users);
// Register triggers
$ins_users->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1"
$ins_users->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$ins_users->registerTrigger("END", "Trigger_Default_Redirect", 99, "test.php"
// Add columns
$ins_users->setTable("users"
$ins_users->addColumn("first_name", "STRING_TYPE", "POST", "first_name"
$ins_users->addColumn("last_name", "STRING_TYPE", "POST", "last_name"
$ins_users->addColumn("email_address", "STRING_TYPE", "POST", "email_address"
$ins_users->addColumn("username", "STRING_TYPE", "POST", "username"
$ins_users->addColumn("languages", "STRING_TYPE", "POST", "languages"
$ins_users->addColumn("currencies", "STRING_TYPE", "POST", "currencies"
$ins_users->addColumn("password", "STRING_TYPE", "POST", "password"
$ins_users->addColumn("signup_date", "DATE_TYPE", "POST", "signup_date"
$ins_users->setPrimaryKey("userid", "NUMERIC_TYPE"
// Execute all the registered transactions
$tNGs->executeTransactions();
// Get the transaction recordset
$rsusers = $tNGs->getRecordset("users"
$row_rsusers = mysql_fetch_assoc($rsusers);
$totalRows_rsusers = mysql_num_rows($rsusers);
?><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test</title>
<link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="includes/common/js/base.js" type="text/javascript"></script>
<script src="includes/common/js/utility.js" type="text/javascript"></script>
<script src="includes/skins/style.js" type="text/javascript"></script>
<?php echo $tNGs->displayValidationRules();?>
<style type="text/css">
<!--
.style2 {color: #999999}
-->
</style>
</head>
<body>
<?php
echo $tNGs->getErrorMsg();
?>
<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
<table cellpadding="2" cellspacing="0" class="KT_tngtable">
<tr>
<td class="KT_th"><span class="style2">
<label for="first_name">First_name:</label>
</span></td>
<td><input type="text" name="first_name" id="first_name" value="<?php echo KT_escapeAttribute($row_rsusers['first_name']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("first_name"?> <?php echo $tNGs->displayFieldError("users", "first_name" ?> </td>
</tr>
<tr>
<td class="KT_th"><span class="style2">
<label for="last_name">Last_name:</label>
</span></td>
<td><input type="text" name="last_name" id="last_name" value="<?php echo KT_escapeAttribute($row_rsusers['last_name']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("last_name"?> <?php echo $tNGs->displayFieldError("users", "last_name" ?> </td>
</tr>
<tr>
<td class="KT_th"><span class="style2">
<label for="email_address">Email_address:</label>
</span></td>
<td><input type="text" name="email_address" id="email_address" value="<?php echo KT_escapeAttribute($row_rsusers['email_address']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("email_address"?> <?php echo $tNGs->displayFieldError("users", "email_address" ?> </td>
</tr>
<tr>
<td class="KT_th"><span class="style2">
<label for="username">Username:</label>
</span></td>
<td><input type="text" name="username" id="username" value="<?php echo KT_escapeAttribute($row_rsusers['username']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("username"?> <?php echo $tNGs->displayFieldError("users", "username" ?> </td>
</tr>
<tr>
<td class="KT_th"><span class="style2">
<label for="languages">Languages:</label>
</span></td>
<td><select name="languages" size="3" multiple id="languages">
<?php
do {
?>
<option value="<?php echo $row_languages['sb_desc']?>"<?php if (!(strcmp($row_languages['sb_desc'], $row_rsusers['languages']))) {echo "SELECTED";} ?>><?php echo $row_languages['sb_desc']?></option>
<?php
} while ($row_languages = mysql_fetch_assoc($languages));
$rows = mysql_num_rows($languages);
if($rows > 0) {
mysql_data_seek($languages, 0);
$row_languages = mysql_fetch_assoc($languages);
}
?>
</select>
<?php echo $tNGs->displayFieldError("users", "languages" ?> </td>
</tr>
<tr>
<td class="KT_th"><span class="style2">
<label for="currencies">Currencies:</label>
</span></td>
<td><select name="currencies" size="3" multiple id="currencies">
<?php
do {
?>
<option value="<?php echo $row_currencies['sb_desc']?>"<?php if (!(strcmp($row_currencies['sb_desc'], $row_rsusers['currencies']))) {echo "SELECTED";} ?>><?php echo $row_currencies['sb_desc']?></option>
<?php
} while ($row_currencies = mysql_fetch_assoc($currencies));
$rows = mysql_num_rows($currencies);
if($rows > 0) {
mysql_data_seek($currencies, 0);
$row_currencies = mysql_fetch_assoc($currencies);
}
?>
</select>
<?php echo $tNGs->displayFieldError("users", "currencies" ?> </td>
</tr>
<tr>
<td class="KT_th"><span class="style2">
<label for="password">Password:</label>
</span></td>
<td><input type="text" name="password" id="password" value="<?php echo KT_escapeAttribute($row_rsusers['password']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("password"?> <?php echo $tNGs->displayFieldError("users", "password" ?> </td>
</tr>
<tr>
<td class="KT_th"><span class="style2">
<label for="signup_date">Signup_date:</label>
</span></td>
<td><input type="text" name="signup_date" id="signup_date" value="<?php echo KT_formatDate($row_rsusers['signup_date']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("signup_date"?> <?php echo $tNGs->displayFieldError("users", "signup_date" ?> </td>
</tr>
<tr class="KT_buttons">
<td colspan="2"><input name="KT_Insert1" type="submit" id="KT_Insert1" value="Insert record" /> </td>
</tr>
</table>
</form>
<p> </p>
</body>
</html><?php
mysql_free_result($languages);
mysql_free_result($currencies);
?>
First, you need to rename your form's select tag from name="Type" to name="Type[]". Putting those brackets in at the end
of the name will make it so that when PHP receives the form contents it will turn them into an array. Then you have to take
DW's usual insert record code and put it within a loop that loops through each of the array items. Here's an example:
// set it up
reset ($languages); // this sets the array pointer to the beginning of the array
mysql_select_db($database, $db);
// loop through array of languages[] and write each instance to db
while (list($key, $val) = each ($languages)) {
$insertSQL = sprintf("INSERT INTO users (languages) VALUES (%s)",
GetSQLValueString($val, "text");
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
} // end loop
Note that you also need to have the GetSQLValueString function on the page somewhere. DW automatically inserts this
function whenever you do an insert record behavior. You can copy and paste it from another page if you like.
Also be sure to have the include file to your connection settings somewhere on the page.
i have the same Problem,
where must i insert the code in my Site,
here is the Code of my Recordset:
Thanks for Helping.
Best Regards
Tim
<?php require_once('Connections/local.php'); ?>
<?php
// Load the common classes
require_once('includes/common/KT_common.php');
// Load the tNG classes
require_once('includes/tng/tNG.inc.php');
// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher(""
// Make unified connection variable
$conn_local = new KT_connection($local, $database_local);
// Start trigger
$formValidation = new tNG_FormValidation();
$tNGs->prepareValidation($formValidation);
// End trigger
if (!function_exists("GetSQLValueString") {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string" ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
mysql_select_db($database_local, $local);
$query_languages = "SELECT * FROM sbdtng_languages ORDER BY sbdtng_languages.sb_desc";
$languages = mysql_query($query_languages, $local) or die(mysql_error());
$row_languages = mysql_fetch_assoc($languages);
$totalRows_languages = mysql_num_rows($languages);
mysql_select_db($database_local, $local);
$query_currencies = "SELECT * FROM sbdtng_currencies_all ORDER BY sbdtng_currencies_all.sb_desc";
$currencies = mysql_query($query_currencies, $local) or die(mysql_error());
$row_currencies = mysql_fetch_assoc($currencies);
$totalRows_currencies = mysql_num_rows($currencies);
// Make an insert transaction instance
$ins_users = new tNG_insert($conn_local);
$tNGs->addTransaction($ins_users);
// Register triggers
$ins_users->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1"
$ins_users->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$ins_users->registerTrigger("END", "Trigger_Default_Redirect", 99, "test.php"
// Add columns
$ins_users->setTable("users"
$ins_users->addColumn("first_name", "STRING_TYPE", "POST", "first_name"
$ins_users->addColumn("last_name", "STRING_TYPE", "POST", "last_name"
$ins_users->addColumn("email_address", "STRING_TYPE", "POST", "email_address"
$ins_users->addColumn("username", "STRING_TYPE", "POST", "username"
$ins_users->addColumn("languages", "STRING_TYPE", "POST", "languages"
$ins_users->addColumn("currencies", "STRING_TYPE", "POST", "currencies"
$ins_users->addColumn("password", "STRING_TYPE", "POST", "password"
$ins_users->addColumn("signup_date", "DATE_TYPE", "POST", "signup_date"
$ins_users->setPrimaryKey("userid", "NUMERIC_TYPE"
// Execute all the registered transactions
$tNGs->executeTransactions();
// Get the transaction recordset
$rsusers = $tNGs->getRecordset("users"
$row_rsusers = mysql_fetch_assoc($rsusers);
$totalRows_rsusers = mysql_num_rows($rsusers);
?><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test</title>
<link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="includes/common/js/base.js" type="text/javascript"></script>
<script src="includes/common/js/utility.js" type="text/javascript"></script>
<script src="includes/skins/style.js" type="text/javascript"></script>
<?php echo $tNGs->displayValidationRules();?>
<style type="text/css">
<!--
.style2 {color: #999999}
-->
</style>
</head>
<body>
<?php
echo $tNGs->getErrorMsg();
?>
<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
<table cellpadding="2" cellspacing="0" class="KT_tngtable">
<tr>
<td class="KT_th"><span class="style2">
<label for="first_name">First_name:</label>
</span></td>
<td><input type="text" name="first_name" id="first_name" value="<?php echo KT_escapeAttribute($row_rsusers['first_name']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("first_name"?> <?php echo $tNGs->displayFieldError("users", "first_name" ?> </td>
</tr>
<tr>
<td class="KT_th"><span class="style2">
<label for="last_name">Last_name:</label>
</span></td>
<td><input type="text" name="last_name" id="last_name" value="<?php echo KT_escapeAttribute($row_rsusers['last_name']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("last_name"?> <?php echo $tNGs->displayFieldError("users", "last_name" ?> </td>
</tr>
<tr>
<td class="KT_th"><span class="style2">
<label for="email_address">Email_address:</label>
</span></td>
<td><input type="text" name="email_address" id="email_address" value="<?php echo KT_escapeAttribute($row_rsusers['email_address']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("email_address"?> <?php echo $tNGs->displayFieldError("users", "email_address" ?> </td>
</tr>
<tr>
<td class="KT_th"><span class="style2">
<label for="username">Username:</label>
</span></td>
<td><input type="text" name="username" id="username" value="<?php echo KT_escapeAttribute($row_rsusers['username']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("username"?> <?php echo $tNGs->displayFieldError("users", "username" ?> </td>
</tr>
<tr>
<td class="KT_th"><span class="style2">
<label for="languages">Languages:</label>
</span></td>
<td><select name="languages" size="3" multiple id="languages">
<?php
do {
?>
<option value="<?php echo $row_languages['sb_desc']?>"<?php if (!(strcmp($row_languages['sb_desc'], $row_rsusers['languages']))) {echo "SELECTED";} ?>><?php echo $row_languages['sb_desc']?></option>
<?php
} while ($row_languages = mysql_fetch_assoc($languages));
$rows = mysql_num_rows($languages);
if($rows > 0) {
mysql_data_seek($languages, 0);
$row_languages = mysql_fetch_assoc($languages);
}
?>
</select>
<?php echo $tNGs->displayFieldError("users", "languages" ?> </td>
</tr>
<tr>
<td class="KT_th"><span class="style2">
<label for="currencies">Currencies:</label>
</span></td>
<td><select name="currencies" size="3" multiple id="currencies">
<?php
do {
?>
<option value="<?php echo $row_currencies['sb_desc']?>"<?php if (!(strcmp($row_currencies['sb_desc'], $row_rsusers['currencies']))) {echo "SELECTED";} ?>><?php echo $row_currencies['sb_desc']?></option>
<?php
} while ($row_currencies = mysql_fetch_assoc($currencies));
$rows = mysql_num_rows($currencies);
if($rows > 0) {
mysql_data_seek($currencies, 0);
$row_currencies = mysql_fetch_assoc($currencies);
}
?>
</select>
<?php echo $tNGs->displayFieldError("users", "currencies" ?> </td>
</tr>
<tr>
<td class="KT_th"><span class="style2">
<label for="password">Password:</label>
</span></td>
<td><input type="text" name="password" id="password" value="<?php echo KT_escapeAttribute($row_rsusers['password']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("password"?> <?php echo $tNGs->displayFieldError("users", "password" ?> </td>
</tr>
<tr>
<td class="KT_th"><span class="style2">
<label for="signup_date">Signup_date:</label>
</span></td>
<td><input type="text" name="signup_date" id="signup_date" value="<?php echo KT_formatDate($row_rsusers['signup_date']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("signup_date"?> <?php echo $tNGs->displayFieldError("users", "signup_date" ?> </td>
</tr>
<tr class="KT_buttons">
<td colspan="2"><input name="KT_Insert1" type="submit" id="KT_Insert1" value="Insert record" /> </td>
</tr>
</table>
</form>
<p> </p>
</body>
</html><?php
mysql_free_result($languages);
mysql_free_result($currencies);
?>
First, you need to rename your form's select tag from name="Type" to name="Type[]". Putting those brackets in at the end
of the name will make it so that when PHP receives the form contents it will turn them into an array. Then you have to take
DW's usual insert record code and put it within a loop that loops through each of the array items. Here's an example:
// set it up
reset ($languages); // this sets the array pointer to the beginning of the array
mysql_select_db($database, $db);
// loop through array of languages[] and write each instance to db
while (list($key, $val) = each ($languages)) {
$insertSQL = sprintf("INSERT INTO users (languages) VALUES (%s)",
GetSQLValueString($val, "text");
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
} // end loop
Note that you also need to have the GetSQLValueString function on the page somewhere. DW automatically inserts this
function whenever you do an insert record behavior. You can copy and paste it from another page if you like.
Also be sure to have the include file to your connection settings somewhere on the page.
Replied 26 Jul 2007 22:52:50
26 Jul 2007 22:52:50 Charity Babcock replied:
(I just emailed the following to Julian, but if anyone else has a solution, I would LOVE to hear!) Thanks!
Hi Julian!
About a year ago, you posted on a FWZone Forum a solution for uploading arrays to a database. I've found the information incredibly helpful, but am running into a small problem and was wondering if you had any ideas as to what I can do to fix it. I would be eternally grateful.
You posted the following:
Posted - 11 Aug 2006 : 11:33:44
This is a very late reply, but may be helpful to someone in the future. Basically, you can't really use DW's built-in behaviors to take a multiple select list and perform an insert record. You can, but only the last selection in the list will be inserted. In order to get all the multiple selections inserted into the database, you have to do some hand-coding.
First, you need to rename your form's select tag from name="Type" to name="Type[]". Putting those brackets in at the end of the name will make it so that when PHP receives the form contents it will turn them into an array. Then you have to take DW's usual insert record code and put it within a loop that loops through each of the array items. Here's an example:
// set it up
reset ($Type); // this sets the array pointer to the beginning of the array
mysql_select_db($database, $db);
// loop through array of Type[] and write each instance to db
while (list($key, $val) = each ($Type)) {
$insertSQL = sprintf("INSERT INTO yourtable (yourfield) VALUES (%s)",
GetSQLValueString($val, "text");
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
} // end loop
Note that you also need to have the GetSQLValueString function on the page somewhere. DW automatically inserts this function whenever you do an insert record behavior. You can copy and paste it from another page if you like. Also be sure to have the include file to your connection settings somewhere on the page.
______________
I've done this on my page, and it looks like this:
reset($specialty);
mysql_select_db($database_connection, $connection);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "memberinfo");
while (list($key, $val) = each ($specialty)) {
$insertSQL = sprintf("INSERT INTO specialty_group (specialty, member_id) VALUES (%s,LAST_INSERT_ID())",
GetSQLValueString($val, "text",
GetSQLValueString($_REQUEST['member_id'], "int");
mysql_select_db($database_connection, $connection);
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
_____________________
My problem is this: the code performs perfectly, creating a new row in the table for each item selected in the list, along with their member_id. BUT, I get an error at the top of the page that reads
"Warning: reset() [function.reset]: Passed variable is not an array or object in /home/.alcuin/wiltern/aialosangeles.org/database/memberinfo.php on line 87
Warning: Variable passed to each() is not an array or object in /home/.alcuin/wiltern/aialosangeles.org/database/memberinfo.php on line 90"
I've tried to create an array using $specialty = array("adaptive reuse","art" and etc...
But it screws up how the data is entered and gives me the value "Array" in the database.
I love the result of your code, but don't know what to do to get rid of the pesky error message!
Any ideas you have would be most appreciated.
Thanks!
Hi Julian!
About a year ago, you posted on a FWZone Forum a solution for uploading arrays to a database. I've found the information incredibly helpful, but am running into a small problem and was wondering if you had any ideas as to what I can do to fix it. I would be eternally grateful.
You posted the following:
Posted - 11 Aug 2006 : 11:33:44
This is a very late reply, but may be helpful to someone in the future. Basically, you can't really use DW's built-in behaviors to take a multiple select list and perform an insert record. You can, but only the last selection in the list will be inserted. In order to get all the multiple selections inserted into the database, you have to do some hand-coding.
First, you need to rename your form's select tag from name="Type" to name="Type[]". Putting those brackets in at the end of the name will make it so that when PHP receives the form contents it will turn them into an array. Then you have to take DW's usual insert record code and put it within a loop that loops through each of the array items. Here's an example:
// set it up
reset ($Type); // this sets the array pointer to the beginning of the array
mysql_select_db($database, $db);
// loop through array of Type[] and write each instance to db
while (list($key, $val) = each ($Type)) {
$insertSQL = sprintf("INSERT INTO yourtable (yourfield) VALUES (%s)",
GetSQLValueString($val, "text");
$Result1 = mysql_query($insertSQL, $db) or die(mysql_error());
} // end loop
Note that you also need to have the GetSQLValueString function on the page somewhere. DW automatically inserts this function whenever you do an insert record behavior. You can copy and paste it from another page if you like. Also be sure to have the include file to your connection settings somewhere on the page.
______________
I've done this on my page, and it looks like this:
reset($specialty);
mysql_select_db($database_connection, $connection);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "memberinfo");
while (list($key, $val) = each ($specialty)) {
$insertSQL = sprintf("INSERT INTO specialty_group (specialty, member_id) VALUES (%s,LAST_INSERT_ID())",
GetSQLValueString($val, "text",
GetSQLValueString($_REQUEST['member_id'], "int");
mysql_select_db($database_connection, $connection);
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
_____________________
My problem is this: the code performs perfectly, creating a new row in the table for each item selected in the list, along with their member_id. BUT, I get an error at the top of the page that reads
"Warning: reset() [function.reset]: Passed variable is not an array or object in /home/.alcuin/wiltern/aialosangeles.org/database/memberinfo.php on line 87
Warning: Variable passed to each() is not an array or object in /home/.alcuin/wiltern/aialosangeles.org/database/memberinfo.php on line 90"
I've tried to create an array using $specialty = array("adaptive reuse","art" and etc...
But it screws up how the data is entered and gives me the value "Array" in the database.
I love the result of your code, but don't know what to do to get rid of the pesky error message!
Any ideas you have would be most appreciated.
Thanks!