problema con insert e update

  • Creatore Discussione Creatore Discussione gotiche
  • Data di inizio Data di inizio

gotiche

Nuovo Utente
19 Ago 2010
2
0
0
Ciao a tutti ho questo codice
PHP:
<?php include './page.php';
HtmlHeader();
Navigation();
$message = "";
if (isset($_GET['alert']))
{
if ($_GET['alert'] == 0)
{
$message = "Dati scritti correttamente nel database";
}
if ($_GET['alert'] == 1)
{
$message = "ERRORE: Nessun dato scritto nel database.<br>Campo NOME deve essere compilato!";
}
}
echo "<br><br>";
echo $message;
?>
<table> <br> <br>
<form action="insert_data.php" method="POST"> <tr> <td>Nome</td> <td>
<input type="text" maxlength="10" name="nome" /><br></td</tr> <tr> <td>Gen</td> <td> <input type="text" maxlength="1" name="gen" /><br></td></tr> <tr> <td>Feb</td> <td> <input type="text" maxlength="1" name="feb" /><br></td></tr> <tr> <td>Mar</td> <td> <input type="text" maxlength="1" name="mar" /><br></td></tr> <tr> <td>Apr</td> <td> <input type="text" maxlength="1" name="apr" /><br></td></tr> <tr> <td>Mag</td> <td> <input type="text" maxlength="1" name="mag" /><br></td></tr> <tr> <td>Giu</td> <td> <input type="text" maxlength="1" name="giu" /><br></td></tr> <tr> <td>Lug</td> <td> <input type="text" maxlength="1" name="lug" /><br></td></tr> <tr> <td>Ago</td> <td> <input type="text" maxlength="1" name="ago" /><br></td></tr> <tr> <td>Set</td> <td> <input type="text" maxlength="1" name="set" /><br></td></tr> <tr> <td>Ott</td> <td> <input type="text" maxlength="1" name="ott" /><br></td></tr> <tr> <td>Nov</td> <td> <input type="text" maxlength="1" name="nov" /><br></td></tr> <tr> <td>Dic</td> <td> <input type="text" maxlength="1" name="dic" /><br></td></tr> <tr><td><br>
<input type="submit" value="inserisci" /></td</tr> </form> </table>
<?php
HtmlFooter();
?>

nella pagine insert.php
e questo codice

PHP:
<?php
if (empty($_POST['nome']) )
{
header("Location: insert.php?alert=1");
die;
}
include "./connect.php";
$sql = "INSERT INTO telematici (nome,gen,feb,mar,apr,mag,giu,lug,ago,set) VALUES ('$_POST[nome]','$_POST[gen]','$_POST[feb]','$_POST[mar]','$_POST[apr]','$_POST[mag]','$_POST[giu]','$_POST[lug]','$_POST[ago]','$_POST[set]')";
mysql_query($sql, $conn);
header("Location: insert.php?alert=0");
?>

nella pagina insert_data.php

il mio problema e' che se nella pagina insert_data.php aggiungo dei valori non inserisce nessun dato, se cancello tra le parentesi tonde il set e il '$_POST[set]' magicamente funzione.. la stessa cosa me lo fa con il comdando UPDATE. Ci sono limitazioni per questi due comandi?
 
Scusa, ma hai una minima concezione di cosa sia o di come funzioni un DB? Non puoi mica aggiungere campi a piacere in una query. Deve esserci una corrispondenza con la struttura delle tabelle nel DB. Nel tuo caso sul DB nella tabella tematici hai una serie di campi che nominati gen, feb ecc. Ovviamente se vuoi aggiungere dei campi non basta farlo nella query, è necessario modificare prima la struttura del DB aggiungendo i nuovi campi prima di poterli valorizzare e/o modificare.
 
ciao, i campi sono gia' presenti nel DB, io devo fare in modo che mi crei dei record nuovi e questo lo fa fino ad ago poi non so perche' si ferma
 

Discussioni simili