Topic: Pubblico - Composto da 2 Posts di 2 Utenti.
| 10 Agosto, 2011 09:27 | #1 | ||
|---|---|---|---|
|
Ciao a tutti, CONNESSIONE AL DB 1<?php 2header("Content-Type: text/html; charset=utf-8"); 3 4$hostname = "localhost"; 5$username = ""; 6$password = ""; 7 8$conn = mysql_connect("$hostname","$username","$password"); 9if (!$conn) 10 { 11 echo ('Connessione non riuscita: ' . mysql_error()); 12 exit(); 13 } 14else 15 { 16 echo ("Connessione effettuata con successo"); 17 } 18 19mysql_select_db("mio_db", $conn); 20 21mysql_close($conn); 22 23?> FORM HTML: 1<html> 2<body> 3 <title>INSERIRE DATI DEL DEFUNTO</title> 4<form action="insert_defunto.php" method="post"> 5<!--id: <input type="text" name="id" /> <br> --> 6Nome del defunto: <input type="text" name="nome" /> <br> 7Cognome del defunto: <input type="text" name="cognome" /> <br> 8Anno morte: <input type="text" name="anno_morte" /> <br> 9Cimitero: <input type="text" name="cimitero" /> <br> 10Numero blocco: <input type="text" name="n_blocco" /> <br> 11Numero locazione: <input type="text" name="n_locazione" /> <br> 12Numero lampade: <input type="text" name="n_lampade" /> <br> 13Anno ultimo rinnovo lampade: <input type="text" name="ultimo_rinnovo_lampade" /> <br> 14Anno estumulazione: <input type="text" name="estumulazione" /> <br> 15 16<input type="submit" value="Aggiungi" /> 17</form> 18 19</body> 20</html> PAGINA PHP INSERT: 1<?php 2header("Content-Type: text/html;charset=utf-8"); 3require('connessione.php'); 4 5//$id = $_POST["id"]; 6$nome = $_POST["nome"]; 7$cognome = $_POST["cognome"]; 8$anno_morte = $_POST["anno_morte"]; 9$cimitero = $_POST["cimitero"]; 10$n_blocco = $_POST["n_blocco"]; 11$n_locazione = $_POST["n_locazione"]; 12$n_lampade = $_POST["n_lampade"]; 13$ultimo_rinnovo_lampade = $_POST["ultimo_rinnovo_lampade"]; 14$estumulazione = $_POST["estumulazione"]; 15 16//comando SQL 17 18$strSQL = "INSERT INTO defunti (id_defunto, nome, cognome, anno_morte, cimitero, n_blocco, n_locazione, n_lampade, ultimo_rinnovo_lampade, estumulazione)"; 19$strSQL .= "VALUES ('', '$nome', '$cognome', '$anno_morte', '$cimitero', '$n_blocco', '$n_locazione', '$n_lampade', '$ultimo_rinnovo_lampade', '$estumulazione')"; 20 echo $strSQL; 21 22if (! mysql_query($strSQL)) 23 24{ 25echo ("ERRORE NEL COMANDO INSERT!!!"); 26exit(); 27} 28 29echo ("DEFUNTO AGGIUNTO CORRETTAMENTE"); 30 31mysql_close($conn); 32 33?> il problema principale è che non mi da nessun messaggio d'errore se non quello che ho scritto io nell' if "ERRORE NEL COMANDO INSERT!!!" Come vedete ho fatto un echo della stringa sql così da poterla testare direttamente in phpmyadmin, provandola l'inserimento viene effettuato con successo, ma da form non funziona!!! -.- vi ringrazio in anticipo per l' aiuto. A presto!!!
Ultima modifica 10 Agosto, 2011 09:42 di salentino |
|||
| 10 Agosto, 2011 12:05 | #2 | ||
|---|---|---|---|
|
Che tabella allegra! Per scoprire se c'è la connessione: 1echo mysql_ping() ? 'SI' : 'NO'; Se c'è, fatti dire l'errore da MySQL: 1echo '<p><strong>' . mysql_errno() . ':</strong> ' . mysql_error() . '</p>';
Ultima modifica 10 Agosto, 2011 12:05 di fuser |
|||
Condividi su:
Loggati o Registrati per replicare