Inserire chechbox nel db

Matteo Scirea

Nuovo Utente
16 Gen 2013
3
0
1
Ciao a tutti,
sono nuovo della community. Ho cercato nel forum ma non ho trovato quello che al momento mi serve o forse non l'ho visto.
Sto sviluppando un sito con Joomla ed ho installato un componente che si chiama GMapFP.
Ora ho modificato nella pagina di amministrazione un campo text (che viene correttamente salvato nel database) con una serie di chechbox. La mia necessità è quella di salvare le chechbox selezionate nel campo del database (che è di tipo varchar).

Il codice che ho modificato è il seguente:
PHP:
<?php 
					$checkbox = $_POST['icon_label'];
					for ($i=0; $i<sizeof($checkbox); $i++)
					{
						$var = explode(',',$_POST['icon_label']); 
					}
					echo $var;
				?>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="24hr Room service">
                    	<img src="/templates/gantry/images/clickenya/icons/24hour.png" alt="24hr service"/>
                    </div>
                    <input type="checkbox" name="icon_label[]" id="icon_label" value="24hr" <?php echo strpos($var,"24hr") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Beverages in all rooms">
                    	<img src="/templates/gantry/images/clickenya/icons/in_room_teacoffee.png" alt="Beverages in all rooms"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="beverages" <?php echo strpos($var,"beverages") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Bureau de change EUROS">
                    	<img src="/templates/gantry/images/clickenya/icons/fees_euro.png" alt="Bureau de change EUROS"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="feeseuro" <?php echo strpos($var,"feeseuro") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Bureau de change POUNDS">
                    	<img src="/templates/gantry/images/clickenya/icons/fees_pound.png" alt="Bureau de change POUNDS"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="feespound" <?php echo strpos($var,"feespound") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Bureau de change DOLLARS">
                    	<img src="/templates/gantry/images/clickenya/icons/fees.png" alt="Bureau de change DOLLARS"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="feesdollar" <?php echo strpos($var,"feesdollar") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Disabled access">
                    	<img src="/templates/gantry/images/clickenya/icons/disabled_access.png" alt="Disabled access"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="disabled" <?php echo strpos($var,"disabled") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Gymnasium onsite">
                    	<img src="/templates/gantry/images/clickenya/icons/gym.png" alt="Gymnasium onsite"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="gymonsite" <?php echo strpos($var,"gymonsite") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Hairdresser onsite">
                    	<img src="/templates/gantry/images/clickenya/icons/hairdresser.png" alt="Hairdresser onsite"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="hairdresser" <?php echo strpos($var,"hairdresser") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Hair dryer in every room">
                    	<img src="/templates/gantry/images/clickenya/icons/hairdryer.png" alt="Hair dryer in every room"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="haidryer" <?php echo strpos($var,"haidryer") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Minibar in room">
                    	<img src="/templates/gantry/images/clickenya/icons/room_bar.png" alt="Minibar in room"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="minibar" <?php echo strpos($var,"minibar") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Parking available">
                    	<img src="/templates/gantry/images/clickenya/icons/parking.png" alt="Parking available"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="parking" <?php echo strpos($var,"parking") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Restraunt onsite">
                    	<img src="/templates/gantry/images/clickenya/icons/restaurant.png" alt="Restraunt onsite"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="restaurant" <?php echo strpos($var,"restaurant") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Safe available">
                    	<img src="/templates/gantry/images/clickenya/icons/hotel_safe.png" alt="Safe available"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="hotel_safe" <?php echo strpos($var,"hotel_safe") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Showers in every room">
                    	<img src="/templates/gantry/images/clickenya/icons/shower_only.png" alt="Showers in every room"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="shower" <?php echo strpos($var,"shower") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Shuttle service to airport and nightclub district available">
                    	<img src="/templates/gantry/images/clickenya/icons/shuttle_service.png" alt="Shuttle service to airport and nightclub district available"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="shuttle_service" <?php echo strpos($var,"shuttle_service") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Wifi available">
                    	<img src="/templates/gantry/images/clickenya/icons/wifi.png" alt="Wifi available"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="wifi" <?php echo strpos($var,"wifi") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Internet access available">
                    	<img src="/templates/gantry/images/clickenya/icons/internet.png" alt="Internet access available"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="internet" <?php echo strpos($var,"internet") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Air conditioning in all rooms">
                    	<img src="/templates/gantry/images/clickenya/icons/air_conditioning.png" alt="Air conditioning in all rooms"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="air_conditioning" <?php echo strpos($var,"air_conditioning") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="All inclusive">
                    	<img src="/templates/gantry/images/clickenya/icons/allinc.png" alt="All inclusive"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="allinc" <?php echo strpos($var,"allinc") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Baby Friendly">
                    	<img src="/templates/gantry/images/clickenya/icons/baby_friendly.png" alt="Baby Friendly"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="baby_friendly" <?php echo strpos($var,"baby_friendly") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Beach">
                    	<img src="/templates/gantry/images/clickenya/icons/beach.png" alt="Beach"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="beach" <?php echo strpos($var,"beach") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Board Walk">
                    	<img src="/templates/gantry/images/clickenya/icons/board_walk.png" alt="Board Walk"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="board_walk" <?php echo strpos($var,"board_walk") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Canoeing available">
                    	<img src="/templates/gantry/images/clickenya/icons/canoeing.png" alt="Canoeing available"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="canoeing" <?php echo strpos($var,"canoeing") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Fishing available">
                    	<img src="/templates/gantry/images/clickenya/icons/fishing.png" alt="Fishing available"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="fishing" <?php echo strpos($var,"fishing") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Iron in all rooms">
                    	<img src="/templates/gantry/images/clickenya/icons/iron.png" alt="Iron in all rooms"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="iron" <?php echo strpos($var,"iron") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Jacuzzi in all rooms">
                    	<img src="/templates/gantry/images/clickenya/icons/jacuzzi.png" alt="Jacuzzi in all rooms"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="jacuzzi" <?php echo strpos($var,"jacuzzi") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Pool available">
                    	<img src="/templates/gantry/images/clickenya/icons/pool.png" alt="Pool available"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="pool" <?php echo strpos($var,"pool") === false ? '' : 'checked'  ?>  >
                </div>
                <div style="float : left; text-align:center;" >
                	<div id="24hr" title="Telephone in all rooms">
                    	<img src="/templates/gantry/images/clickenya/icons/room_telephone.png" alt="Telephone in all rooms"/>
                    </div>
					<input type="checkbox" name="icon_label[]" id="icon_label" value="room_telephone" <?php echo strpos($var,"room_telephone") == false ? '' : 'checked'  ?>  >
                </div>
               <?php
					$checkbox = $_POST['icon_label'];
					for ($i=0; $i<sizeof($checkbox); $i++)
					{
						if (isset($_POST['icon_label']))
						$tot_value = implode(',',$_POST['icon_label']); 
					}
					$this->gmapfp->icon_label = $tot_value; 
				?>
Purtroppo provando a stampare il campo $this->gmapfp->icon_label non viene visualizzato nulla e infatti nel database vedo NULL

Potete gentilmente aiutarmi?
Sono un neofita di php e sicuramente si vede...
Grazie a tutti...
 

Nefyt

Utente Attivo
17 Apr 2012
1.102
0
0
Dove esegui la query?

Inoltre non ho ben capito cosa intendevi con
PHP:
$this->gmapfp->icon_label = $tot_value;
Forse cosi?
PHP:
$gmapfp = new ClassGmap(); //cambia il nome
$gmapfp->icon_label = $tot_value;
 

Matteo Scirea

Nuovo Utente
16 Gen 2013
3
0
1
Dove esegui la query?

Inoltre non ho ben capito cosa intendevi con
PHP:
$this->gmapfp->icon_label = $tot_value;
Forse cosi?
PHP:
$gmapfp = new ClassGmap(); //cambia il nome
$gmapfp->icon_label = $tot_value;
Ciao Nefyt e grazie per la risposta.
Dunque io sto usando joomla e ammetto di avere delle difficoltà a trovare le query di accesso al db...

Il codice originale che ho modificato era il seguente:
<input class="inputbox" type="text" name="icon_label" id="icon_label" size="60" value="<?php echo str_replace('"', '&quot;',$this->gmapfp->icon_label); ?>" />

Come puoi vedere l'istruzioni $this->gmapfp->icon_label consente di recuperare/scrivere/modificare il campo del db icon_label.

Pensavo che utilizzando l'istruzione $this->gmapfp->icon_label = $tot_value; sarei riuscito a passare i dati delle varie checkbox (che volevo concatenare nella variabile $tot_value) al campo del db. Stampando però ho visto che la variabile $tot_value risulta non essere inizializzata. Il problema è che tutto il codice viene eseguito dall'interfaccia del componente che ho utilizzato in joomla, e ho paura che i comandi $_POST non vengono gestiti come quelli di una normale pagina php .