PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > <input type="checkbox">
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
<input type="checkbox">

Réponse
 
LinkBack Outils de la discussion
Vieux 15/03/2008, 04h00   #1
John Taylor-Johnston
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut <input type="checkbox">

Am coding something. Cannot quite clear my head. I know what my SQL
looks like. I just cannot see clearly to input it.
What is $_POST["checkregion"] going to look like? Is it going to have
all the convenient commas I will need in my SQL? Or do I have to parse
God knows how many checkboxes?
John

<input type="text" name="Name">
<label><input type="checkbox" name="checkregion" value="Knowlton">A</label>
<label><input type="checkbox" name="checkregion" value="Thetford
Mines">A</label>


$sql ='insert into `database`.`table` (`Nom` ,`checkregion`)
values ('John', 'Knowlton,Thetford Mines') ';


CREATE TABLE IF NOT EXISTS `GLApplications` (
`Name` varchar(200) NOT NULL,
set(''Knowlton','Thetford Mines','Clarenceville','Sawyerville','Laval')
NOT NULL,
`dummy` int(10) NOT NULL auto_increment,
PRIMARY KEY (`dummy`)
)
  Réponse avec citation
Vieux 15/03/2008, 04h12   #2
John Taylor-Johnston
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: <input type="checkbox">

http://www.glquebec.org/English/test.php
When I check "Knowlton" and "Thetford Mines" or others, only "Thetford
Mines" shows up in phpinfo(). $_POST["checkregion"] only sees "Thetford
Mines".
What am I doing wrong? How do I parse value checkregion? Or set this up
differently?

> <input type="text" name="Name">
> <label><input type="checkbox" name="checkregion" value="Knowlton">A</label>
> <label><input type="checkbox" name="checkregion" value="Thetford
> Mines">A</label>
>
>
> CREATE TABLE IF NOT EXISTS `GLApplications` (
> `Name` varchar(200) NOT NULL,
> set(''Knowlton','Thetford Mines','Clarenceville','Sawyerville','Laval')
> NOT NULL,
> `dummy` int(10) NOT NULL auto_increment,
> PRIMARY KEY (`dummy`)
> )


  Réponse avec citation
Vieux 15/03/2008, 04h14   #3
John Taylor-Johnston
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: <input type="checkbox">

$_POST["checkregion"] is supposed to be an array, no?

John Taylor-Johnston wrote:
> http://www.glquebec.org/English/test.php
> When I check "Knowlton" and "Thetford Mines" or others, only "Thetford
> Mines" shows up in phpinfo(). $_POST["checkregion"] only sees
> "Thetford Mines".
> What am I doing wrong? How do I parse value checkregion? Or set this
> up differently?
>
>> <input type="text" name="Name">
>> <label><input type="checkbox" name="checkregion"
>> value="Knowlton">A</label>
>> <label><input type="checkbox" name="checkregion" value="Thetford
>> Mines">A</label>
>>
>>
>> CREATE TABLE IF NOT EXISTS `GLApplications` (
>> `Name` varchar(200) NOT NULL,
>> set(''Knowlton','Thetford
>> Mines','Clarenceville','Sawyerville','Laval') NOT NULL,
>> `dummy` int(10) NOT NULL auto_increment,
>> PRIMARY KEY (`dummy`)
>> )

>
>

  Réponse avec citation
Vieux 15/03/2008, 04h22   #4
Robert Cummings
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: <input type="checkbox">


On Fri, 2008-03-14 at 23:14 -0400, John Taylor-Johnston wrote:
> $_POST["checkregion"] is supposed to be an array, no?


You want the following (otherwise each checked entry overwrites the
previous):

<input type="checkbox" name="checkregion[]" value="Knowlton" />
<input type="checkbox" name="checkregion[]" value="Thetford Mines" />

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

  Réponse avec citation
Vieux 15/03/2008, 04h30   #5
John Taylor-Johnston
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: <input type="checkbox">

Ah! ok,

Array
(
[0] => Hemmingford
[1] => Huntingdon
)

How do I set up my $sql?

$sql ='insert into `database`.`table` (`Nom` ,`checkregion`)
values ('John', '".implode(',', $_POST['myvalues']."') ';


.... Hey!! What is this?

Diagnostic-Code: smtp; 550-5.7.1 mail rejected by policy. SURBL hit
550-Spammy
URLs in your message 550 See
http://master.php.net/mail/why.php?why=SURBL


Robert Cummings wrote:
> On Fri, 2008-03-14 at 23:14 -0400, John Taylor-Johnston wrote:
>> $_POST["checkregion"] is supposed to be an array, no?

>
> You want the following (otherwise each checked entry overwrites the
> previous):
>
> <input type="checkbox" name="checkregion[]" value="Knowlton" />
> <input type="checkbox" name="checkregion[]" value="Thetford Mines" />
>
> Cheers,
> Rob.

  Réponse avec citation
Vieux 15/03/2008, 05h16   #6
John Taylor-Johnston
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: <input type="checkbox">

Will this do it?

> $sql ='insert into `database`.`table` (`Nom` ,`checkregion`)
> values ('John', '".implode(',', serialise($_POST['checkregion'])."') ';


http://ca.php.net/manual/en/function.serialize.php


> Array
> (
> [0] => Hemmingford
> [1] => Huntingdon
> )
>
>> <input type="checkbox" name="checkregion[]" value="Knowlton" />
>> <input type="checkbox" name="checkregion[]" value="Thetford Mines" />

  Réponse avec citation
Vieux 15/03/2008, 05h18   #7
John Taylor-Johnston
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: <input type="checkbox">

Sorry, will this work?

$sql ='insert into `database`.`table` (`Nom` ,`checkregion`)
values ('John', '".serialise($_POST['checkregion'])."') ';


John Taylor-Johnston wrote:
> Will this do it?
>
> > $sql ='insert into `database`.`table` (`Nom` ,`checkregion`)
> > values ('John', '".implode(',', serialise($_POST['checkregion'])."') ';

>
> http://ca.php.net/manual/en/function.serialize.php
>
>
>> Array
>> (
>> [0] => Hemmingford
>> [1] => Huntingdon
>> )
>>
>>> <input type="checkbox" name="checkregion[]" value="Knowlton" />
>>> <input type="checkbox" name="checkregion[]" value="Thetford Mines" />

  Réponse avec citation
Vieux 15/03/2008, 05h23   #8
Robert Cummings
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: <input type="checkbox">


On Sat, 2008-03-15 at 00:18 -0400, John Taylor-Johnston wrote:
> Sorry, will this work?
>
> $sql ='insert into `database`.`table` (`Nom` ,`checkregion`)
> values ('John', '".serialise($_POST['checkregion'])."') ';


Depends on what you want to do with the data. But you've certainly
spelled serialize() wrong as it regards usage in PHP.

Cheers,
Rob.



>
>
> John Taylor-Johnston wrote:
> > Will this do it?
> >
> > > $sql ='insert into `database`.`table` (`Nom` ,`checkregion`)
> > > values ('John', '".implode(',', serialise($_POST['checkregion'])."') ';

> >
> > http://ca.php.net/manual/en/function.serialize.php
> >
> >
> >> Array
> >> (
> >> [0] => Hemmingford
> >> [1] => Huntingdon
> >> )
> >>
> >>> <input type="checkbox" name="checkregion[]" value="Knowlton" />
> >>> <input type="checkbox" name="checkregion[]" value="Thetford Mines" />

>

--
http://www.interjinn.com
Application and Templating Framework for PHP

  Réponse avec citation
Vieux 15/03/2008, 05h33   #9
John Taylor-Johnston
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: <input type="checkbox">

Robert,

>>>> Array
>>>> (
>>>> [0] => Hemmingford
>>>> [1] => Huntingdon
>>>> )

> You want the following (otherwise each checked entry overwrites the
> previous):
> <input type="checkbox" name="checkregion[]" value="Knowlton" />
> <input type="checkbox" name="checkregion[]" value="Thetford Mines" />


How would you proceed?

$sql ='insert into `database`.`table` (`Nom` ,`checkregion`)
values ('John', '". ?? ."') ';

I'm just guessing.

  Réponse avec citation
Vieux 15/03/2008, 05h52   #10
Robert Cummings
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: <input type="checkbox">


On Sat, 2008-03-15 at 00:33 -0400, John Taylor-Johnston wrote:
> Robert,
>
> >>>> Array
> >>>> (
> >>>> [0] => Hemmingford
> >>>> [1] => Huntingdon
> >>>> )

> > You want the following (otherwise each checked entry overwrites the
> > previous):
> > <input type="checkbox" name="checkregion[]" value="Knowlton" />
> > <input type="checkbox" name="checkregion[]" value="Thetford Mines" />

>
> How would you proceed?
>
> $sql ='insert into `database`.`table` (`Nom` ,`checkregion`)
> values ('John', '". ?? ."') ';
>
> I'm just guessing.


It depend son what you want to do with the data. It may be that you want
a row for every selected entry or it may be that you can just serialize
the data. Do you want to just have a snapshot of what the user chose? Or
do you want to be able to query the database about who selected
"Knowlton"? If the former, then you can get away with just serializing
the data, but if you want to be able to do queries, then you need to
store each entry in its own row.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

  Réponse avec citation
Vieux 15/03/2008, 06h00   #11
John Taylor-Johnston
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: <input type="checkbox">

Robert Cummings wrote:
> On Sat, 2008-03-15 at 00:33 -0400, John Taylor-Johnston wrote:
>> Robert,
>>
>>>>>> Array
>>>>>> (
>>>>>> [0] => Hemmingford
>>>>>> [1] => Huntingdon
>>>>>> )
>>> You want the following (otherwise each checked entry overwrites the
>>> previous):
>>> <input type="checkbox" name="checkregion[]" value="Knowlton" />
>>> <input type="checkbox" name="checkregion[]" value="Thetford Mines" />

>> How would you proceed?
>>
>> $sql ='insert into `database`.`table` (`Nom` ,`checkregion`)
>> values ('John', '". ?? ."') ';
>>
>> I'm just guessing.

>
> It depend son what you want to do with the data. It may be that you want
> a row for every selected entry or it may be that you can just serialize
> the data. Do you want to just have a snapshot of what the user chose? Or
> do you want to be able to query the database about who selected
> "Knowlton"? If the former, then you can get away with just serializing
> the data, but if you want to be able to do queries, then you need to
> store each entry in its own row.
>
> Cheers,
> Rob.


It would look like:

$sql ='insert into `database`.`table` (`Nom` ,`checkregion`)
values ('John', 'Montreal,Knowlton,anything') ';

checkregion[5] = "Montreal";
checkregion[7] = "Knowlton";
checkregion[55] = "anything";

I need to unarray checkregion[] and break it up into separate words and
then separate them by commas.

Hmm?
  Réponse avec citation
Vieux 15/03/2008, 06h55   #12
Robert Cummings
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: <input type="checkbox">


On Sat, 2008-03-15 at 01:00 -0400, John Taylor-Johnston wrote:
> Robert Cummings wrote:
> > On Sat, 2008-03-15 at 00:33 -0400, John Taylor-Johnston wrote:
> >> Robert,
> >>
> >>>>>> Array
> >>>>>> (
> >>>>>> [0] => Hemmingford
> >>>>>> [1] => Huntingdon
> >>>>>> )
> >>> You want the following (otherwise each checked entry overwrites the
> >>> previous):
> >>> <input type="checkbox" name="checkregion[]" value="Knowlton" />
> >>> <input type="checkbox" name="checkregion[]" value="Thetford Mines" />
> >> How would you proceed?
> >>
> >> $sql ='insert into `database`.`table` (`Nom` ,`checkregion`)
> >> values ('John', '". ?? ."') ';
> >>
> >> I'm just guessing.

> >
> > It depend son what you want to do with the data. It may be that you want
> > a row for every selected entry or it may be that you can just serialize
> > the data. Do you want to just have a snapshot of what the user chose? Or
> > do you want to be able to query the database about who selected
> > "Knowlton"? If the former, then you can get away with just serializing
> > the data, but if you want to be able to do queries, then you need to
> > store each entry in its own row.
> >
> > Cheers,
> > Rob.

>
> It would look like:
>
> $sql ='insert into `database`.`table` (`Nom` ,`checkregion`)
> values ('John', 'Montreal,Knowlton,anything') ';
>
> checkregion[5] = "Montreal";
> checkregion[7] = "Knowlton";
> checkregion[55] = "anything";
>
> I need to unarray checkregion[] and break it up into separate words and
> then separate them by commas.


$regions = implode( ',', $checkregion );

$sql =
"INSERT INTO `database`.`table` "
."( "
." `Nom`, "
." `checkregion` "
.") "
."VALUES "
."( "
." '".mysql_real_escape_string( $nom, $conn )."', "
." '".mysql_real_escape_string( $regions, $conn )."' "
.") ";

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

  Réponse avec citation
Vieux 15/03/2008, 17h38   #13
larry@portcommodore.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: <input type="checkbox">


check out this discussion:
http://groups.google.com/group/alt.p...1216c72ba62a99
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h46.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,19926 seconds with 21 queries