Jump to content

Recommended Posts

I have a dynamic category list, I have printed those list with check box in the form. I have to check those boxes and submit. How can I pick all checked value in action page? Right now only one value passing from several check boxes while several check boxes checked.

 

This is my form

 

<form name="entryform" action="cat_sec_submit.php" method="post">

<?

$row = mysql_fetch_object($result);

 

echo $row->org_id . ', ';

echo $row->org_name . '<br>';

 

?>

 

<?

$query1 = "SELECT * FROM category";

 

$result1 = mysql_query($query1);

 

?>

 

<?

 

while ($row1 =  mysql_fetch_object($result1))

 

{$cat = "$row1->cat_name";

$value = "$row1->value";

echo "<input name= \"cat_list\" type=\"checkbox\" name=\"checkbox\" value=\"$value\" />" . "$cat" ;}

 

 

?>

 

<input type="submit" name="Submit" value="Submit" />

<input name="h1" type="hidden" id="h1" value="<?php echo $_GET['id'];?>">

</form>

 

 

This is Action Page

 

 

<?

$id = $_POST['h1'];

 

if($_POST['Submit']!="")

 

{$query = ("insert into org_option (org_id, cat_list) values ('$id', '$_POST[cat_list]')");

 

$insert = mysql_query($query);

echo "insert into org_option (org_id, cat_list) values ('$id', '$_POST[cat_list]')";

 

if ($insert)

echo '<b>Sucessfully Added Organizaton Details</b> ';

}

 

echo "<input name= \"cat_list\" type=\"checkbox\" name=\"checkbox\" value=\"$value\" />" . "$cat" ;}

 

So good they named it twice !

 

add [] to the name

 

echo "<input name= \"cat_list[]\" type=\"checkbox\" value=\"$value\" />" . "$cat" ;}

 

then

foreach ($cat_list as $value)
{
  //process value
}

Thanks for helping me.

It is working.

 

I need more help. I am trying to insert checked value into one field and in one record. But I failed.

 

 

The status of my pages is:

 

/*** Entry Form *****/ 

 

<form name="entryform" action="cat_sec_submit.php" method="post">

<?

$row = mysql_fetch_object($result);

 

echo $row->org_id . ', ';

echo $row->org_name . '<br>';

 

?>

 

<?

$query1 = "SELECT * FROM category";

 

$result1 = mysql_query($query1);

 

?>

 

<?

 

while ($row1 =  mysql_fetch_object($result1))

 

{$cat = "$row1->cat_name";

$value = "$row1->value";

echo "<input name= \"cat_list[]\" type=\"checkbox\" name=\"checkbox\" value=\"$value\">" . "$cat" ;}

//echo "$row1->sec_list";

 

 

?>

 

<input type="submit" name="Submit" value="Submit" />

<input name="h1" type="hidden" id="h1" value="<?php echo $_GET['id'];?>">

</form>

 

 

 

/**** Action Page ********/

 

<?

$id = $_POST['h1'];

 

$cat_list1 =  $_POST[cat_list];

$value1 =  $_POST[$value];

 

 

foreach ($cat_list1 as $value1)

{

echo $value1;

}

if($_POST['Submit']!="")

 

{$insert = mysql_query("insert into org_option (org_id, cat_list) values ('$id', '$value1')");

 

if ($insert)

echo '<b>Sucessfully Added Organizaton Details</b>';

}

 

In addition I am sending my table snapshot by attached.

 

[attachment deleted by admin]

is this what you wanted?

 

<?php
/**** Action Page ********/
if (isset($_POST['Submit']))
{
    $id = $_POST['h1'];

    $cat_list1 =  $_POST[cat_list];

    $errors=0;
    foreach ($cat_list1 as $value1)
    {
        echo $value1;
        $insert = mysql_query("insert into org_option (org_id, cat_list) values ('$id', '$value1')");
        if (!$insert) $errors++;
    }

    if (!$errors)
        echo 'Sucessfully Added Organizaton Details';
    
}
?>

Thanks for your reply.

 

Actually I wanted to insert all checked value in one field at a time. This is sample value e, p, n etc. When they are selected then I would like to insert them this way 'epn'

 

Is this a way?

 

I tried hard but don't understand which is the right way. Your help would be appreciated.

 

- Roobon

First, take a look at this line and tell me what is wrong with it.

 

<?php
echo "<input name= \"cat_list[]\" type=\"checkbox\" name=\"checkbox\" value=\"$value\">" . "$cat" ;}
?>

 

There is a problem that will wreak havoc on you. Rather than tell you what it is, I wanna see if you can tell me :)

 

 

Also, I find that escaping a shitload of quotes is too tedious. try it like this.

 

<?php
echo '<input name="cat_list[]" type="checkbox" name="checkbox" value="'.$value.'">'.$cat;
?>

 

It is a lot cleaner and will help find errors (which I duplicated in my line of code :) )

 

 

<?php
/**** Action Page ********/
if (isset($_POST['Submit']))
{
    $id = $_POST['h1'];

    $cat_list1 =  $_POST[cat_list];

    $value1 = join('', $cat_list);

    echo $value1;

    $insert = mysql_query("insert into org_option (org_id, cat_list) values ('$id', '$value1')");

    if ($insert)
        echo 'Sucessfully Added Organizaton Details';
    
}
?>
[

 

However, if you are going to need to query the org_id tables and category tables together I'd reccomend the separate records approach. (google 'data normalization ')

Thanks for your recommendation.

 

:) :)

 

First, take a look at this line and tell me what is wrong with it.

 

<?php
echo "<input name= \"cat_list[]\" type=\"checkbox\" name=\"checkbox\" value=\"$value\">" . "$cat" ;}
?>

 

There is a problem that will wreak havoc on you. Rather than tell you what it is, I wanna see if you can tell me :)

 

 

Also, I find that escaping a shitload of quotes is too tedious. try it like this.

 

<?php
echo '<input name="cat_list[]" type="checkbox" name="checkbox" value="'.$value.'">'.$cat;
?>

 

It is a lot cleaner and will help find errors (which I duplicated in my line of code :) )

 

 

Excellent Suggestion. It is working. I am also keeping your recommendation in my mind.

 

Thanks a lot for being with me.

 

:) :) Roobon

 

 

<?php
/**** Action Page ********/
if (isset($_POST['Submit']))
{
    $id = $_POST['h1'];

    $cat_list1 =  $_POST[cat_list];

    $value1 = join('', $cat_list);

    echo $value1;

    $insert = mysql_query("insert into org_option (org_id, cat_list) values ('$id', '$value1')");

    if ($insert)
        echo 'Sucessfully Added Organizaton Details';
    
}
?>
[

 

However, if you are going to need to query the org_id tables and category tables together I'd reccomend the separate records approach. (google 'data normalization ')

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.