Page 1 of 1

how to save all dynamic checkboxes value in one table.(mysq)

Posted: Fri Apr 20, 2007 6:59 am
by phpkets
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi everyone,
i have no. of dynamic checboxes in my form.
now not able to figure out in this code that how can i save all checkbox values in one table.

[b]my DB table's format is :[/b]

[syntax="sql"]mas_id int(11) NOT NULL auto_increment,
name varchar(20) NOT NULL default '',
que_id text NOT NULL,
php code looks like :[/syntax]

Code: Select all

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$que_id = '';
foreach($_POST["que_id"] AS $key => $value){
$insertSQL = sprintf("INSERT INTO ts_masterset (que_id, name) VALUES (%s, %s)",
GetSQLValueString($_POST['que_id'], "text"),
GetSQLValueString($_POST['name'], "text"));}
and my html code looks like, where i am generating all questions :

Code: Select all

<?php $questionsInclude = mysql_query("SELECT * FROM ts_questions WHERE setid='".$row_tsset['id']."'");
while($aquestionsInclude = mysql_fetch_array($questionsInclude)){
$qd = $aquestionsInclude['id'];
echo "<input name='que_id[]' type='checkbox' value='$qd'>";
echo $aquestionsInclude['question'];
echo "<br>"; }?>
but with this code i am getting "Array" as a value in database.

anyidea, where i am doing wrong !
thanks.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Apr 20, 2007 10:01 am
by guitarlvr
for starters i think the $questionsInclude = line should look something like this:

Code: Select all

$questionsInclude = mysql_query("SELECT * FROM ts_questions WHERE setid='$row_tsset['id']'");
Give that a try (changed select statement slightly).

Wayne

Posted: Fri Apr 20, 2007 10:26 am
by arturm
You SQL look OK

you have an array in the database because $_POST['que_id'] is an array

try this

Code: Select all

foreach($_POST["que_id"] AS $key => $value) {
    $insertSQL = sprintf("INSERT INTO ts_masterset (que_id, name) VALUES (%s, %s)",
    GetSQLValueString($value, "text"),
    GetSQLValueString($_POST['name'], "text"));
}
I don't know what function GetSQLValueString does but I assume it is just some security validation.

Posted: Mon Apr 23, 2007 12:22 am
by phpkets
arturm wrote:You SQL look OK

you have an array in the database because $_POST['que_id'] is an array

try this

Code: Select all

foreach($_POST["que_id"] AS $key => $value) {
    $insertSQL = sprintf("INSERT INTO ts_masterset (que_id, name) VALUES (%s, %s)",
    GetSQLValueString($value, "text"),
    GetSQLValueString($_POST['name'], "text"));
}
thanks for your reply.

but adding just $value, its saving just last checkbox value not all.

any other solution for this ?
thanks.