Re: checkboxes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Great - Thanks. That worked fine. Now the next question. ;)
How can I update MySQL with the array values I just generated?
Basically if you checked two checkboxes, that represents two rows in MySQL. How can I update those two rows in the DB?


code snippet
Array: Array ( [0] => Done (completed) [1] => 1 (user_id) [2] => Northeast Ridge (route_name) [3] => 2(id) [4] => Done [5] => 1 [6] => Kahiltna Spire [7] => 4 )


$com = array("$_POST[completed]", "$_POST[route_name]", "$_POST[id]", "$_POST[user_id]");
print_r ($completed);
//foreach ($com as $key => $values) {
include "include/db.php";
$query = "UPDATE ticklist SET completed = '$completed' WHERE route_name = '$route_name' AND id = '$id' AND user_id = '$user_id'";
echo $query;
$msg = "<span style='color:red'>Could not insert record</span>";
$result = mysql_query($query,$db) or die(mysql_error($msg));


Thanks - CH

On Jan 21, 2005, at 3:47 PM, Hutchins, Richard wrote:

You can't just echo out an array. You have to either use print_r() or
iterate over it with a while or for...next loop. But if you just want to see
what's in the array, print_r() it.


As to why it doesn't bring over the other checkboxes...

If you have (pseudocode)
<html>
<form name="myform" method="post" action="myupdate.php">
<input type="checkbox" name="completed[]" value="value1">&nbsp;Checkbox 1
<input type="checkbox" name="completed[]" value="value2">&nbsp;Checkbox 2
<input type="checkbox" name="completed[]" value="value3">&nbsp;Checkbox 3
</form>
</html>


And you check the first two checkboxes, then the resulting array will be
(pseudocode again):
completed(value1,value2)


And from there, you just access the array contents as you would with any
other multidimensional array.


If you don't check anything on the page, then the array will be empty and, I
think, won't even be sent in the $_POST array. I'm sure somebody will
correct me there if my memory has failed me.


-----Original Message-----
From: Craig Hoffman [mailto:choffman@xxxxxxxxxx]
Sent: Friday, January 21, 2005 4:32 PM
To: php-db@xxxxxxxxxxxxx
Cc: Richard Hutchins
Subject: Re:  checkboxes


I've tried that and it still doesn't bring over the other checkboxes that have been checked. Plus when I echo it out I get Array instead of the variable name.


On Jan 21, 2005, at 3:14 PM, Hutchins, Richard wrote:

Probably all you need to do is name your checkboxes as an array thusly:

name="completed[]"

Then you can access the array on your update page and do whatever you
wish
with it.

Hope this helps.

Rich

-----Original Message-----
From: Craig Hoffman [mailto:choffman@xxxxxxxxxx]
Sent: Friday, January 21, 2005 4:03 PM
To: php-db@xxxxxxxxxxxxx
Subject:  checkboxes


I have a form that display's a checkbox if the value is NULL. The form is in a do... while loop, so the user may check multiple checkboxes. I am trying to pass the variable of each checkboxes to an update statement in MySQL. THe problem is I am only getting one of the checkboxes, even if all of them are checked. Here is my code block, any help would be great. - Craig

//From form page
<form>
  <input type='checkbox' name='completed' value='Done' >
</form>

//MySQL Update Page
$email = $_POST['email'] == $route;
		$completed = $_POST["completed"] == $route;
		 $route_name = trim($_POST["route_name"]) == $route;
		$user_id = $_POST['user_id'] == $route;
			$id = $_POST['id'] == $route;

$route = array(id => "$_POST[id]", completed => "$_POST[completed]",
route_name => "$_POST[route_name]", user_id => "$_POST[user_id]");

             foreach ($route as $key => $values) {
                    echo("<br />");
                    echo $values;
                   //MySQL Update statement will go here.
		}

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux