close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Php code for inserting group checkbox data into the database

Thread began 3/16/2011 6:39 am by sandeep.kesarwani423749 | Last modified 11/25/2014 11:50 pm by sandeep.kesarwani423749 | 3935 views | 4 replies

Jason ByrnesWebAssist

you would need to hand code a loop to loop through the array, and use an insert to inner teach array piece, this will take hand coding to accomplish.

Here is a very simplistic example that shows how to do this;

<?php require_once('Connections/localhost.php'); ?>
<?php require_once("webassist/database_management/wa_appbuilder_php.php"); ?>
<?php
//if statement to make sure the checkbox group has a value
if(isset($_POST["CheckboxGroup1"])) {
//foreach loop added to loop through checkbox array
foreach($_POST["CheckboxGroup1"] as $k => $v) {
?>
<?php
// WA DataAssist Insert
if ($_SERVER["REQUEST_METHOD"] == "POST") // Trigger
{
$WA_connection = $localhost;
$WA_table = "options";
$WA_sessionName = "OptionID";
$WA_redirectURL = "";
if (function_exists("rel2abs")) $WA_redirectURL = $WA_redirectURL?rel2abs($WA_redirectURL,dirname(__FILE__)):"";
$WA_keepQueryString = false;
$WA_indexField = "OptionID";
$WA_fieldNamesStr = "OptionName";
// original biunding for the checkbox form element
//$WA_fieldValuesStr = "".((isset($_POST["CheckboxGroup1"]))?$_POST["CheckboxGroup1"]:"") ."";
// edited to use the $v variable created by the for each loop
$WA_fieldValuesStr = "".($v) ."";
$WA_columnTypesStr = "',none,''";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode($WA_AB_Split, $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_localhost;
mysql_select_db($WA_connectionDB, $WA_connection);
@session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
<?php
} //end foreach
} // end if
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
<p>
<label>
<input type="checkbox" name="CheckboxGroup1[]" value="Item 1" id="CheckboxGroup1_0" />
Item 1</label>
<br />
<label>
<input type="checkbox" name="CheckboxGroup1[]" value="Item 2" id="CheckboxGroup1_1" />
Item 2</label>
<br />
<br />
<label>
<input type="submit" name="button" id="button" value="Submit" />
</label>
<br />
</p>
</form>
</body>
</html>



if you need more assistance, were can help through a premiere support appointment:
http://www.webassist.com/premier_request.php

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...