Ciao a tutti ho un problema dovuto alla mia poca dimestichezza con il php...Ho fatto un banalissimo script che salva dentro due tabelle del mio DB dei tutorials...
Il problema è questo sò creare questi tutorials...Sò inserirli nel DB ma una volta inseriti non so come modificarli...Cosi ho pensato richiamo il contenuto che mi interessa in un form e poi lo riprocesso...
Ho fatto nel modo seguente...Prima di tutto creo una pg dove posso selezionare il tutorials che mi serve e lo invio alla pag edit.php
[code:1:a1d1536679]echo " <a href=\"edit.php?id=$row[id]\"> ;modifica</a>";[/code:1:a1d1536679]
Fin qui tutto bene poi ho creato una PAG che inserisca i dati ricevuti (non tutti solo quelli che mi interessano modificare)
la pagina chiaramente è edit.php ora la mostro
[code:1:a1d1536679]<? include("top_foot.inc.php"); include("config.inc.php"); top();
$db = mysql_connect($db_host, $db_user, $db_password);
if ($db == FALSE)
die ("Errore nella connessione. Verificare i parametri nel file config.inc.php");
mysql_select_db($db_name, $db)
or die ("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
$query = "SELECT id,titolo, sintesi, indice_1, testo_1, indice_2, testo_2, indice_3, testo_3, indice_4, testo_4, indice_5, testo_5, indice_6, testo_6, indice_7, testo_7, data, tutorials.nome AS autore, mail FROM tutorials LEFT JOIN autori_tutorials ON tutorials.nome = autori_tutorials.nome WHERE id='$id'";
$result = mysql_query($query, $db);
$row = mysql_fetch_array($result);
echo "<p>Articolo Numero $row[id]</p>";
echo "<form method=post action=modifica.php>";
echo "Titolo:<br>";
echo "<input type=text size=40 name=titolo value=\"$row[titolo]\"><br >";
echo "<br>";
echo "Sintesi:<br>";
echo "<textarea cols=34 rows=3 name=sintesi>$row[sintesi]</textarea><br>";
echo "<br>";
echo "Autore:<br>";
echo "<input type=text size=40 name=autore value=\"$row[autore]\"><br >";
echo "<br>";
echo "E-mail:<br>";
echo "<input type=text size=40 name=mail value=\"$row[mail]\"><br&g t;";
echo "<br>";
echo "1- Indice:<br>";
echo "<input type=text size=40 name=indice_1 value=\"$row[indice_1]\">< br>";
echo "<br>";
echo "1- Testo:<br>";
echo "<textarea cols=34 rows=10 name=testo_1>$row[testo_1]</textarea><br>";
echo "<br>";
echo "2- Indice:<br>";
echo "<input type=text size=40 name=indice_2 value=\"$row[indice_2]\">< br>";
echo "<br>";
echo "2- Testo:<br>";
echo "<textarea cols=34 rows=10 name=testo_2>$row[testo_2]</textarea><br>";
echo "<br>";
echo "3- Indice:<br>";
echo "<input type=text size=40 name=indice_3 value=\"$row[indice_3]\">< br>";
echo "<br>";
echo "3- Testo:<br>";
echo "<textarea cols=34 rows=10 name=testo_3>$row[testo]3</textarea><br>";
echo "<br>";
echo "4- Indice:<br>";
echo "<input type=text size=40 name=indice_4 value=\"$row[indice_4]\">< br>";
echo "<br>";
echo "4- Testo:<br>";
echo "<textarea cols=34 rows=10 name=testo_4>$row[testo_4]</textarea><br>";
echo "<br>";
echo "5- Indice:<br>";
echo "<input type=text size=40 name=indice_5 value=\"$row[indice_5]\">< br>";
echo "<br>";
echo "5- Testo:<br>";
echo "<textarea cols=34 rows=10 name=testo_5>$row[testo_5]</textarea><br>";
echo "<br>";
echo "6- Indice:<br>";
echo "<input type=text size=40 name=indice_6 value=\"$row[indice_6]\">< br>";
echo "<br>";
echo "6- Testo:<br>";
echo "<textarea cols=34 rows=10 name=testo_6>$row[testo_6]</textarea><br>";
echo "<br>";
echo "7- Indice:<br>";
echo "<input type=text size=40 name=indice_7 value=\"$row[indice_7]\">< br>";
echo "<br>";
echo "7- Testo:<br>";
echo "<textarea cols=34 rows=10 name=testo_7>$row[testo_7]</textarea><br>";
echo "<br>";
echo "Password:<br>";
echo "<input type=password size=40 name=pass><br>";
echo "<br><input type=submit value=Invia></form>";
mysql_close($db);
foot();
?>[/code:1:a1d1536679]
Fatto questo invio tutto alla pagina modifica.php questa però non funziona come io vorrei e non so dove ho sbagliato...
[code:1:a1d1536679]<? include("top_foot.inc.php");
include("config.inc.php");
top();
if ($pass != $password):
echo "Password errata";
elseif (trim($titolo) == "" OR trim($testo_1) == ""):
echo "I campi Titolo e Testo devono essere riempiti!";
else:
$titolo = addslashes(stripslashes($titolo));
$autore = addslashes(stripslashes($autore));
$mail = addslashes(stripslashes($mail));
$testo_1 = addslashes(stripslashes($testo_1)) ;
$titolo = str_replace("<", "&lt;", $titolo);
$titolo = str_replace(">", "&gt;", $titolo);
$autore = str_replace("<", "&lt;", $autore);
$autore = str_replace(">", "&gt;", $autore);
$testo_1 = str_replace("<", "&lt;", $testo_1);
$testo_1 = str_replace(">", "&gt;", $testo_1);
$testo_1 = nl2br($testo_1);
$testo_1 = str_replace("]", ">", $testo_1);
$testo_1 = str_replace("[URL=", "<a href=", $testo_1);
$testo_1 = str_replace("[/URL", "<a", $testo_1);
$testo_1 = str_replace("[IMG=", "<img src=", $testo_1);
$testo_1 = str_replace("[CODE", "<code", $testo_1);
$testo_1 = str_replace("[/CODE", "</code", $testo_1);
$testo_1 = str_replace("[QUOTE", "<blockquote", $testo_1);
$testo_1 = str_replace("[/QUOTE", "</blockquote", $testo_1);
$testo_2 = str_replace("<", "&lt;", $testo_2);
$testo_2 = str_replace(">", "&gt;", $testo_2);
$testo_2 = nl2br($testo_2);
$testo_2 = str_replace("]", ">", $testo_2);
$testo_2 = str_replace("[URL=", "<a href=", $testo_2);
$testo_2 = str_replace("[/URL", "<a", $testo_2);
$testo_2 = str_replace("[IMG=", "<img src=", $testo_2);
$testo_2 = str_replace("[CODE", "<code", $testo_2);
$testo_2 = str_replace("[/CODE", "</code", $testo_2);
$testo_2 = str_replace("[QUOTE", "<blockquote", $testo_2);
$testo_2 = str_replace("[/QUOTE", "</blockquote", $testo_2);
$testo_3 = str_replace("<", "&lt;", $testo_3);
$testo_3 = str_replace(">", "&gt;", $testo_3);
$testo_3 = nl2br($testo_3);
$testo_3 = str_replace("]", ">", $testo_3);
$testo_3 = str_replace("[URL=", "<a href=", $testo_3);
$testo_3 = str_replace("[/URL", "<a", $testo_3);
$testo_3 = str_replace("[IMG=", "<img src=", $testo_3);
$testo_3 = str_replace("[CODE", "<code", $testo_3);
$testo_3 = str_replace("[/CODE", "</code", $testo_3);
$testo_3 = str_replace("[QUOTE", "<blockquote", $testo_3);
$testo_3 = str_replace("[/QUOTE", "</blockquote", $testo_3);
$testo_4 = str_replace("<", "&lt;", $testo_4);
$testo_4 = str_replace(">", "&gt;", $testo_4);
$testo_4 = nl2br($testo_4);
$testo_4 = str_replace("]", ">", $testo_4);
$testo_4 = str_replace("[URL=", "<a href=", $testo_4);
$testo_4 = str_replace("[/URL", "<a", $testo_4);
$testo_4 = str_replace("[IMG=", "<img src=", $testo_4);
$testo_4 = str_replace("[CODE", "<code", $testo_4);
$testo_4 = str_replace("[/CODE", "</code", $testo_4);
$testo_4 = str_replace("[QUOTE", "<blockquote", $testo_4);
$testo_4 = str_replace("[/QUOTE", "</blockquote", $testo_4);
$testo_5 = str_replace("<", "&lt;", $testo_5);
$testo_5 = str_replace(">", "&gt;", $testo_5);
$testo_5 = nl2br($testo_5);
$testo_5 = str_replace("]", ">", $testo_5);
$testo_5 = str_replace("[URL=", "<a href=", $testo_5);
$testo_5 = str_replace("[/URL", "<a", $testo_5);
$testo_5 = str_replace("[IMG=", "<img src=", $testo_5);
$testo_5 = str_replace("[CODE", "<code", $testo_5);
$testo_5 = str_replace("[/CODE", "</code", $testo_5);
$testo_5 = str_replace("[QUOTE", "<blockquote", $testo_5);
$testo_5 = str_replace("[/QUOTE", "</blockquote", $testo_5);
$testo_6 = str_replace("<", "&lt;", $testo_6);
$testo_6 = str_replace(">", "&gt;", $testo_6);
$testo_6 = nl2br($testo_6);
$testo_6 = str_replace("]", ">", $testo_6);
$testo_6 = str_replace("[URL=", "<a href=", $testo_6);
$testo_6 = str_replace("[/URL", "<a", $testo_6);
$testo_6 = str_replace("[IMG=", "<img src=", $testo_6);
$testo_6 = str_replace("[CODE", "<code", $testo_6);
$testo_6 = str_replace("[/CODE", "</code", $testo_6);
$testo_6 = str_replace("[QUOTE", "<blockquote", $testo_6);
$testo_6 = str_replace("[/QUOTE", "</blockquote", $testo_6);
$testo_7 = str_replace("<", "&lt;", $testo_7);
$testo_7 = str_replace(">", "&gt;", $testo_7);
$testo_7 = nl2br($testo_7);
$testo_7 = str_replace("]", ">", $testo_7);
$testo_7 = str_replace("[URL=", "<a href=", $testo_7);
$testo_7 = str_replace("[/URL", "<a", $testo_7);
$testo_7 = str_replace("[IMG=", "<img src=", $testo_7);
$testo_7 = str_replace("[CODE", "<code", $testo_7);
$testo_7 = str_replace("[/CODE", "</code", $testo_7);
$testo_7 = str_replace("[QUOTE", "<blockquote", $testo_7);
$testo_7 = str_replace("[/QUOTE", "</blockquote", $testo_7);
$data = mktime("0", "0", "0", $mese, $giorno, $anno);
$db = mysql_connect($db_host, $db_user, $db_password);
if ($db == FALSE)
die ("Errore nella connessione. Verificare i parametri nel file config.inc.php");
mysql_select_db($db_name, $db)
or die ("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
$query1 = "INSERT INTO tutorials (id, titolo, sintesi, indice_1, testo_1, indice_2, testo_2, indice_3, testo_3, indice_4, testo_4, indice_5, testo_5, indice_6, testo_6, indice_7, testo_7, data, nome) VALUES ('$id', '$titolo', '$sintesi', '$indice_1', '$testo_1', '$indice_2', '$testo_2', '$indice_3', '$testo_3', '$indice_4', '$testo_4', '$indice_5', '$testo_5', '$indice_6', '$testo_6', '$indice_7', '$testo_7', '$data', '$autore')";
$query2 = "INSERT IGNORE INTO autori_tutorials (nome, mail) VALUES ('$autore', '$mail')";
if (mysql_query($query1, $db) AND mysql_query($query2, $db))
echo "L'articolo è stato inserito correttamente";
else
echo "Erorre durante l'inserimento
$query";
endif;
foot();
?>[/code:1:a1d1536679]
Ora siccome quando ho creato la tabella ho detto che il campo ID doveva essere incrementato automaticamente dal server ho pensato che mi bastava inserirlo manualmente nella query per fare in modo che php sovrascriva il contenuto della riga con ID uguale a quella che ho fornita io...Ma non è cosi...
Le mie modifiche fengono salvate...Ma in un nuovo tutorials...
Non so come fare ne tantomeno dove sbaglio...Anch se credo che l'errore sia nella query...
Aspetto vostri consigli...Grazie in anticipo Ciauz