ciao ^^
Stavo facendo un esercizo in cui ho una form in cui ho delle categorie prese dal database e una checkbox messa così ... nn riesco ad inserire il campo della checkbox selezionata nel campo suo apposito nel database e farlo visualizzare nella pagina di conferma.
Ecco i codici :
From Html :
Ecco il codice dell'inserimento:
ecco la pagina di conferma :
Vi posto anche il relativo dump delle tabelle :
Please help me
Stavo facendo un esercizo in cui ho una form in cui ho delle categorie prese dal database e una checkbox messa così ... nn riesco ad inserire il campo della checkbox selezionata nel campo suo apposito nel database e farlo visualizzare nella pagina di conferma.
Ecco i codici :
From Html :
PHP:
<?php // creare una tabella Pubblicazioni e far in modo che nella form sia scelta la categoria ( presa direttamente dal database ) e compaia un campo Pubblicato dove i valori sono presi dal database;
require_once 'config.php';
$conn=new PDO (DSN,USERNAME,PASSWORD);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it-IT">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="robots" content="noindex" />
<meta name="googlebot" content="index" />
<meta name="robots" content="nofollow" />
<title>Titolo</title>
</head>
<body>
<div class="corpo">
<h1>Gestione messaggi</h1>
<form name="messaggi" action="inserimento.php" method="POST">
<p>Codice</p>
<input type="text" name="CODICE"/><br>
<p>Titolo del messaggio</p>
<input type="text" name="Titolo"/><br>
<p> Messaggio</p>
<input type="text" name="messaggio"/><br>
<p> Data</p>
<input type="text" name="data"/><br>
<p> Categoria </p>
<select name="categorie">
<?php
$categorie=$conn->query("SELECT * FROM categorie");
while ($riga=$categorie->fetch()){
echo "<option value='{$riga["Codice"]}'>{$riga["Nome"]}</option>";
}
?>
</select><br>
<input type="checkbox" name="Pubblicato" value="1">Pubblicato <br>
<input type="checkbox" name="Pubblicato_1" value="2">Non Pubblicato <br>
<input type="submit" value="Upload">
</form>
</div>
</body>
</html>
Ecco il codice dell'inserimento:
PHP:
<?php
require 'config.php';
if (isset ($_POST["Pubblicato"] || $_POST["Pubblicato_1"])){
$checkboxValue =1;
$checked = $checkedValue ? ' checked="checked"' : '';
echo "<input type=\"checkbox\"{$checked} />";
$conn=new PDO (DSN,USERNAME,PASSWORD);
$stmt=$conn->prepare("INSERT INTO messaggi_blog (CODICE,Titolo,messaggi,data,categorie,Pubblicazioni)VALUES (?,?,?,?,?,?)");
$stmt->execute(array($_POST["CODICE"],$_POST["Titolo"],$_POST["messaggio"],$_POST["data"],$_POST["categorie"],$_POST["Pubblicato"]));
echo "<meta http-equiv='Refresh' content='100; URL=conferma_pubblicazioni.php'>"; // content senve per decidere i secondi d attesa prima d essere rinviato alla pagina prescelta
}
?>
ecco la pagina di conferma :
PHP:
<?php
require 'config.php';
$conn=new PDO (DSN,USERNAME,PASSWORD);
$stmt=$conn->prepare(" SELECT messaggi_blog.CODICE,messaggi_blog.Titolo,messaggi_blog.messaggi,messaggi_blog.data, categorie.Nome as Codice, messaggi_blog.Pubblicazioni as Pubblica FROM messaggi_blog LEFT JOIN categorie ON categorie=categorie.Codice ORDER BY messaggi_blog.CODICE DESC LIMIT 1");
");
$stmt->execute();
while($ogg=$stmt->fetch()){;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it-IT">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="robots" content="noindex" />
<meta name="googlebot" content="index" />
<meta name="robots" content="nofollow" />
<title>Titolo</title>
</head>
<body>
<div class="corpo">
<h1>Conferma</h1>
<p><strong>Inserimento avvenuto</strong></p>
<p>Codice:<?php echo $ogg["CODICE"]; ?></p>
<p>Titolo:<?php echo $ogg["Titolo"];?></p>
<p>Messaggio <?php echo $ogg["messaggi"];?></p>
<p>Data:<?php echo $ogg["data"];?></p>
<p>Categoria:<?php echo $ogg["Codice"]; ?></p>
<p>Pubblicato:<?php echo$ogg["Pubblica"];} ?></p>
</form>
</div>
</body>
</html>
Vi posto anche il relativo dump delle tabelle :
Codice:
Table structure for table `Pubblicazioni`
--
DROP TABLE IF EXISTS `Pubblicazioni`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `Pubblicazioni` (
`Numero` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`Numero`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `Pubblicazioni`
--
LOCK TABLES `Pubblicazioni` WRITE;
/*!40000 ALTER TABLE `Pubblicazioni` DISABLE KEYS */;
INSERT INTO `Pubblicazioni` VALUES (1),(2);
/*!40000 ALTER TABLE `Pubblicazioni` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `categorie`
--
DROP TABLE IF EXISTS `categorie`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `categorie` (
`Codice` int(11) NOT NULL AUTO_INCREMENT,
`Nome` varchar(150) NOT NULL DEFAULT '',
PRIMARY KEY (`Nome`,`Codice`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `categorie`
--
LOCK TABLES `categorie` WRITE;
/*!40000 ALTER TABLE `categorie` DISABLE KEYS */;
INSERT INTO `categorie` VALUES (1,'Abuso'),(1,'commento'),(1,'segnalazione'),(1,'Violazione norme sul copyright');
/*!40000 ALTER TABLE `categorie` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `messaggi_blog`
--
DROP TABLE IF EXISTS `messaggi_blog`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `messaggi_blog` (
`CODICE` int(11) NOT NULL DEFAULT '0',
`Titolo` varchar(150) DEFAULT NULL,
`messaggi` varchar(150) DEFAULT NULL,
`data` date DEFAULT NULL,
`categorie` varchar(150) DEFAULT NULL,
`Pubblicazioni` int(11) DEFAULT NULL,
PRIMARY KEY (`CODICE`),
KEY `categorie` (`categorie`),
KEY `Pubblicazioni` (`Pubblicazioni`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `messaggi_blog`
--
LOCK TABLES `messaggi_blog` WRITE;
/*!40000 ALTER TABLE `messaggi_blog` DISABLE KEYS */;
INSERT INTO `messaggi_blog` VALUES (0,'','','0000-00-00','1',NULL),(1,'dfdsgs','zfdsgrs','2012-04-13','1',NULL),(123,'dfdsgs','cxbfxb','2011-05-31','1',NULL);
/*!40000 ALTER TABLE `messaggi_blog` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `pubblicazioni`
--
DROP TABLE IF EXISTS `pubblicazioni`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `pubblicazioni` (
`valore` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`valore`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `pubblicazioni`
--
LOCK TABLES `pubblicazioni` WRITE;
/*!40000 ALTER TABLE `pubblicazioni` DISABLE KEYS */;
INSERT INTO `pubblicazioni` VALUES (1),(2);
/*!40000 ALTER TABLE `pubblicazioni` ENABLE KEYS */;
Please help me