Ciao a tutti, vado subito al dunque.
Sto sviluppando un sito in PHP ma sono alle prime armi e quindi ho dei buchi di formazione che sicuramente voi saprete riempire
Devo modificare i record di un tabella, richiamo i valori, e poi faccio UPDATE
Questa pagina funziona correttamente ma tutti i valori che richiamo vengono inseriti tutti in un input type, come segue
$myfield = mysql_fetch_field($dbResult,$k);
print("<tr><td>$myfield->name</td>");
echo("<td><input type=\"text\" maxlenghth=\"10\" size=\"100\" name=\"$myfield->name\" value='");
echo(addslashes($v));
echo("'></td></tr>\n");
quello che vorrei fare io è visualizzare ID DATA TITOLO in input type e DESCRIZIONE nella textarea(nella pagina di inserimento della notizia ho utilizzato un editor [fckeditor] e vorrei che il testo della descrizione riappaia in questo editor)
lascio il codice della pagina di modifica. se serve posso ostare anche il codice della pagina di inserimano
GRAZIE
<html>
<head>
<title>Modifica record</title>
<link rel="stylesheet" type="text/css" media="screen" href="../css/pannello.css" />
</head>
<body>
Codice PHP:
<?php
include("config.inc.php");
$confirm = $_REQUEST['confirm'];
$id = $_REQUEST['id'];
$puntatore_db = mysql_connect($host, $user, $password)
or die ("Errore nella connessione \n".mysql_error());
mysql_select_db($db, $puntatore_db)
or die("Errore:". mysql_error ());
if (!$confirm)
{
$query = "select * from xxx where id=$id";
$dbResult = mysql_query($query, $puntatore_db);
$AffectedRows = mysql_affected_rows($puntatore_db);
if ($AffectedRows==0)
{
print("<h3>Non esistono record con i criteri richiesti</h3>");
}
else
{
mysql_data_seek($dbResult,0);
$row=mysql_fetch_row($dbResult);
print("<table>");
print("<form method=\"post\"action=\"{$_SERVER['PHP_SELF']}\">");
foreach ($row as $k => $v)
{
$myfield = mysql_fetch_field($dbResult,$k);
print("<tr><td>$myfield->name</td>");
echo("<td><input type=\"text\" maxlenghth=\"10\" size=\"100\" name=\"$myfield->name\" value='");
echo(addslashes($v));
echo("'></td></tr>\n");
}
print("<tr><td coldspan=\"2\"><input type=\"submit\" value=\"Conferma modifiche\"></td></tr> ");
print("<input type=\"hidden\" name=\"confirm\" value=\"1\">");
print("</form>");
print("</table>");
mysql_free_result($dbResult);
mysql_close($puntatore_db);
}
}
else
{
$DATA = $_REQUEST['DATA'];
$TITOLO = $_REQUEST['TITOLO'];
$DESCRIZIONE = $_REQUEST['DESCRIZIONE'];
$ID = $_REQUEST['ID'];
$query = "UPDATE xxx SET DATA=\"$DATA\", TITOLO=\"$TITOLO\", DESCRIZIONE=\"$DESCRIZIONE\" where ID=$ID";
$dbResult = mysql_query($query, $puntatore_db);
if (!$dbResult) die ("Errore 3 nella connessione \n".mysql_error());
$AffectedRows = mysql_affected_rows($puntatore_db);
if ($AffectedRows!=0)
{
print("<h3>la news e' stata aggiornata</h3>");
print("<h3><a href=\"gestione.php?pagina=record_tab\">Torna alla lista</a></h3>");
}
mysql_close($puntatore_db);
}
?>
</body>
</html>