innanzi tutto volevo dire che questo è un buon sito O0 infatti ci sono molte risorse sul php (che sto studiando)
ecco il problema
ho creato questo script seguendo il vostro corso
<?
// Mi connetto al database
$conn = mysql_connect("localhost","root","");
mysql_select_db("test", $conn);
if($_POST && isset($_GET['id']))
{
aggiorna_record();
}
elseif(isset($_GET['id']))
{
mostra_record();
}
else mostra_lista();
function mostra_lista()
{
if(isset($_GET['msg']))
echo '<b>'.htmlentities($_GET['msg']).'</b><br /><br />';
$query = "SELECT * FROM orario2A";
$result = mysql_query($query);
if (!$result) {
die("errore nella query: $query" . mysql_error());
}
echo ' <table border="1">
<tr>
<th>ORA</th>
<th>LUNEDI</th>
<th>MARTEDI</th>
<th>MERCOLEDI</th>
<th>GIOVEDI</th>
<th>VENERDI</th>
<th>SABATO</th>
<th>cosa</th>
</tr>';
while ($row=mysql_fetch_assoc($result)) {
$ora = htmlspecialchars($row['ORA']);
$lunedi = htmlspecialchars($row['LUNEDI']);
$martedi = htmlspecialchars($row['MARTEDI']);
$mercoledi = htmlspecialchars($row['MERCOLEDI']);
$giovedi = htmlspecialchars($row['GIOVEDI']);
$venerdi = htmlspecialchars($row['VENERDI']);
$sabato = htmlspecialchars($row['SABATO']);
$link = $_SERVER['PHP_SELF'] . '?id=' . $row['ORA'];
echo "<tr>
<td>$ora</td>
<td>$lunedi</td>
<td>$martedi</td>
<td>$mercoledi</td>
<td>$giovedi</td>
<td>$venerdi</td>
<td>$sabato</td>
<td><a href=\"$link\">modifica</a></td>
</tr>";
}
echo "</table>";
mysql_free_result($result);
mysql_close();
}
function aggiorna_record()
{
// recupero i campi di tipo "stringa"
$lunedi = trim($_POST['LUNEDI']);
$martedi = trim($_POST['MARTEDI']);
$mercoledi = trim($_POST['MERCOLEDI']);
$giovedi = trim($_POST['GIOVEDI']);
$venerdi = trim($_POST['VENERDI']);
$sabato = trim($_POST['SABATO']);
// verifico se devo eliminare gli slash inseriti automaticamente da PHP
if(get_magic_quotes_gpc())
{
$lunedi = stripslashes($lunedi);
$martedi = stripslashes($martedi);
$mercoledi = stripslashes($mercoledi);
$giovedi = stripslashes($giovedi);
$venerdi = stripslashes($venerdi);
$sabato = stripslashes($sabato);
}
// effettuo l'escape dei caratteri speciali per inserirli all'interno della query
$lunedi = mysql_real_escape_string($lunedi);
$martedi = mysql_real_escape_string($martedi);
$mercoledi = mysql_real_escape_string($mercoledi);
$giovedi = mysql_real_escape_string($giovedi);
$venerdi = mysql_real_escape_string($venerdi);
$sabato = mysql_real_escape_string($sabato);
$id = intval($_GET['ORA']);
// verifico la presenza dei campi obbligatori
if(!$lunedi)
{
$msg = urlencode("Non hai inserito il nome");
header("location: $_SERVER[PHP_SELF]?id=$id&msg=$messaggio");
exit;
}
// preparo la query
$query = "UPDATE utenti SET
LUNEDI = '$lunedi',
MARTEDI = '$martedi',
MERCOLEDI = $mercoledi,
GIOVEDI = $giovedi,
VENERDI = $venerdi,
SABATO = '$sabato'
WHERE ORA = $id";
// invio la query
$result = mysql_query($query);
// controllo l'esito
if (!$result) {
die("Errore nella query $query: " . mysql_error());
}
// chiudo la connessione a MySQL
mysql_close();
$messaggio = urlencode('Aggiornamento effettuato con successo');
header("location: $_SERVER[PHP_SELF]?msg=$messaggio");
}
function mostra_record()
{
// mostro un eventuale messaggio
if(isset($_GET['msg']))
echo '<b>'.htmlentities($_GET['msg']).'</b><br /><br />';
$id = intval($_GET['id']);
// preparo la query
$query = "SELECT * FROM orario2A WHERE ORA = $id";
// invio la query
$result = mysql_query($query);
// controllo l'esito
if (!$result) {
die("Errore nella query $query: " . mysql_error());
}
// controllo che la SELECT abbia restituito un record
// l'id passato via GET potrebbe essere stato manipolato
if(mysql_num_rows($result) != 1) {
die("l'ID passato via GET è errato");
}
list($ora,$lunedi,$martedi,$mercoledi,$giovedi,$venerdi,$sabato) = mysql_fetch_row($result);
$lunedi = htmlspecialchars($lunedi);
$martedi = htmlspecialchars($martedi);
$mercoledi = htmlspecialchars($mercoledi);
$giovedi = htmlspecialchars($giovedi);
$venerdi = htmlspecialchars($venerdi);
$sabato = htmlspecialchars($sabato);
?>
<form name="form_registrazione" method="post" action="">
<p>
<label>:ORA
<input name="ora" type="text" value="<?echo $ora?>" />
</label>
</p>
<label>:LUNEDI
<input name="lunedi" type="text" value="<?echo $lunedi?>" />
</label>
<p><label>MARTEDI:
<input name="martedi" type="text" value="<?echo $martedi?>" />
</label> </p>
<p><label>MERCOLEDI:
<input name="mercoledi" type="text" value="<?echo $mercoledi?>" />
</label> </p>
<p><label>GIOVEDI:
<input name="giovedi" type="text" value="<?echo $giovedi?>" />
</label> </p>
<p><label>VENERDI:
<input name="venerdi" type="text" value="<?echo $venerdi?>" />
</label> </p>
<p><label>SABATO:
<input name="sabato" type="text" value="<?echo $sabato?>" />
</label> </p>
<p>
<input name="invia" type="submit" value="Invia" />
</p>
</form>
<?
}
?>
però mi esce sempre l'ID passato via GET è errato
che errore ho fatto??????
grazie O0 O0