RE: Re: checkbox into mysql using php <input type="checkbox" name="list

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

 



if its all going into one col, then implode the array into a string

$data = implode(",",$_POST['games']);

Then insert the data. Still doesn't relieve you of the need to validate the user data.

Bastien

From: "moses Woldeselassie" <mmoses@xxxxxxxxxxx>
To: php-db@xxxxxxxxxxxxx, bastien_k@xxxxxxxxxxx
Subject: RE: Re: checkbox into mysql using php <input type="checkbox" name="list
Date: Thu, 17 Feb 2005 10:21:31 +0000


thank Bastien

I did try that, but the input is going into one column or it is take the last array value and put it each chart in the table.

<input type="checkbox" name="games[]" value="football" />

in that case, these are the value i got in mysql:  f, o, o, t



foreach($_POST['games'] AS $game => $value)
$valuecount = count($_POST['games']);
for($i =0; $i < $valuecount; $i++)
$sql = mysql_query("insert into interest values('$value[0]','$value[1]','$value[2]','$value[3]')");



i'm looking forward to hearing from you.

kind regards;
m




&gt;From: &quot;Bastien Koert&quot; &lt;bastien_k@xxxxxxxxxxx&gt;
&gt;To: mmoses@xxxxxxxxxxx, php-db@xxxxxxxxxxxxx
&gt;Subject: RE: Re: checkbox into mysql using php &lt;input type=&quot;checkbox&quot; name=&quot;list
&gt;Date: Wed, 16 Feb 2005 21:38:10 -0500
&gt;
&gt;$value is not an array...wont run
&gt;
&gt;try
&gt;
&gt;$valuecount = count($_POST['games']);
&gt;
&gt;bastien
&gt;
&gt;&gt;From: &quot;moses Woldeselassie&quot; &lt;mmoses@xxxxxxxxxxx&gt;
&gt;&gt;To: php-db@xxxxxxxxxxxxx
&gt;&gt;Subject: RE: Re: checkbox into mysql using php &lt;input
&gt;&gt;type=&quot;checkbox&quot; name=&quot;list
&gt;&gt;Date: Wed, 16 Feb 2005 22:09:09 +0000
&gt;&gt;
&gt;&gt;Thank you,
&gt;&gt;
&gt;&gt;i don't have any problem using that syntax:
&gt;&gt;if (isset($_POST['submit'])) {
&gt;&gt; echo &quot;You chose the following games:&lt;br /&gt;&quot;;
&gt;&gt; foreach($_POST['games'] AS $game =&gt; $value)
&gt;&gt; $sql = mysql_query(&quot;insert into interest(username)
&gt;&gt;values('$value')&quot;);
&gt;&gt;
&gt;&gt;but the problem is with the following:
&gt;&gt;
&gt;&gt;
&gt;&gt;$valuecount = count($value)
&gt;&gt;for($i =0; $i &lt; $valuecount; $i++) {
&gt;&gt;$sql = mysql_query(&quot;insert into interest values('$value',
&gt;&gt;'$value[$i]')&quot;);
&gt;&gt;
&gt;&gt;I don't get any input into mysql.
&gt;&gt;
&gt;&gt;kind regards
&gt;&gt;m
&gt;&gt;
&gt;&gt;
&gt;&gt;&amp;gt;From: pete M &amp;lt;pmorgan@xxxxxxxx&amp;gt;
&gt;&gt;&amp;gt;To: php-db@xxxxxxxxxxxxx
&gt;&gt;&amp;gt;Subject: Re: checkbox into mysql using php &amp;lt;input
&gt;&gt;type=&amp;quot;checkbox&amp;quot;
&gt;&gt;name=&amp;quot;list[]&amp;quot;value=&amp;quot;x&amp;quot;&amp;gt;
&gt;&gt;&amp;gt;Date: Wed, 16 Feb 2005 18:22:14 +0000
&gt;&gt;&amp;gt;
&gt;&gt;&amp;gt;foreach($_POST['name'] as $k =&amp;gt; $v){
&gt;&gt;&amp;gt;
&gt;&gt;&amp;gt;}
&gt;&gt;&amp;gt;
&gt;&gt;&amp;gt;moses Woldeselassie wrote:
&gt;&gt;&amp;gt;&amp;gt;hi all
&gt;&gt;&amp;gt;&amp;gt;
&gt;&gt;&amp;gt;&amp;gt;
&gt;&gt;&amp;gt;&amp;gt;I need a simple php script to use for html
&gt;&gt;&amp;gt;&amp;gt;
&gt;&gt;&amp;gt;&amp;gt;
&gt;&gt;&amp;gt;&amp;gt;
&gt;&gt;&amp;gt;&amp;gt;&amp;lt;form action=&amp;quot;checkbox.php&amp;quot;
&gt;&gt;method=&amp;quot;post&amp;quot;&amp;gt;
&gt;&gt;&amp;gt;&amp;gt; Select from the list &amp;lt;br /&amp;gt; (check all that
&gt;&gt;apply):&amp;lt;br /&amp;gt;
&gt;&gt;&amp;gt;&amp;gt; &amp;lt;input type=&amp;quot;checkbox&amp;quot;
&gt;&gt;name=&amp;quot;list[]&amp;quot; value=&amp;quot;x&amp;quot;&amp;gt;
&gt;&gt;&amp;gt;&amp;gt; &amp;lt;input type=&amp;quot;checkbox&amp;quot;
&gt;&gt;name=&amp;quot;list[]&amp;quot; value=&amp;quot;y&amp;quot;&amp;gt;
&gt;&gt;&amp;gt;&amp;gt;&amp;lt;input type=&amp;quot;submit&amp;quot; name=&amp;quot;submit&amp;quot;
&gt;&gt;value=&amp;quot;Go!&amp;quot; /&amp;gt;
&gt;&gt;&amp;gt;&amp;gt;&amp;lt;/form&amp;gt;
&gt;&gt;&amp;gt;&amp;gt;
&gt;&gt;&amp;gt;&amp;gt;kind regards
&gt;&gt;&amp;gt;&amp;gt;meberat
&gt;&gt;&amp;gt;
&gt;&gt;&amp;gt;--
&gt;&gt;&amp;gt;PHP Database Mailing List (http://www.php.net/)
&gt;&gt;&amp;gt;To unsubscribe, visit: http://www.php.net/unsub.php
&gt;&gt;&amp;gt;
&gt;&gt;
&gt;&gt;--
&gt;&gt;PHP Database Mailing List (http://www.php.net/)
&gt;&gt;To unsubscribe, visit: http://www.php.net/unsub.php
&gt;&gt;
&gt;
&gt;--
&gt;PHP Database Mailing List (http://www.php.net/)
&gt;To unsubscribe, visit: http://www.php.net/unsub.php
&gt;


--
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