Neanche per me è chiaro il mio stesso codice...
Codice PHP:
include 'db.php';
echo"<form method='post' action='' class='form'>";
echo"<table align='center' class='table'>";
echo "<TR><TD colspan='2' height='30'></TD></TR>";
/*Select per visulazzire le categorie inserendo automaticamente nella casella di testo il nome della categoria*/
echo "<TR><TD class='td' colspan='2' align='center'><select name='nomecategoria'>";
$risultato = mysql_query ("SELECT nomecategoria FROM categorie ORDER BY idcategoria");
while ($row = mysql_fetch_array($risultato,MYSQL_ASSOC))
{
$valore=$row["nomecategoria"];
echo "<option value=\"" . $valore . "\">".$valore."</option>";
}
mysql_free_result($risultato);
echo"</select>";
echo "<input type='submit' value='Copia'></TD></TR>";
$val = $_POST['nomecategoria'];
echo "<TR><TD align='right'><label>[b]Nome Categoria:[/b]</label></TD><TD> <input type='text' name='nomecat' size='30'
value='$val'></TD></TR>";
echo "<TR><TD colspan='2' height='10'></TD></TR>";
echo"<TR><TD align='center' colspan='2'><input type='submit' value='Modifica'></TD></TR>";
echo "<TR><TD colspan='2' height='20'></TD></TR>";
echo "</table>";
/*Modifica nel database della categoria selezionata*/
$dato = $_POST['nomecat'];
if ($dato=='')
echo "vuoto!
";
else{
$modifica = "UPDATE categorie SET nomecategoria='$dato' WHERE nomecategoria='$val'";
echo "
";
mysql_query ($modifica)
or die ("Error");
}
/*Fine modifica*/
echo"</form>";
E' tutto in una pagina! Cosi modifica qualcosa, ma è errato perchè quando clicchi sul tasto modifica si refresha la select e (OVVIAMENTE la WHERE nomecategoria='$val'") torna alla prima categoria modificandola con cio che scrivo nell'area text..