Ho copiato da un libro php uno script che crea dinamicamente un form di modifica dei dati il problema è che non capisco il perchè mi dia sempre questo errore:
Warning: mysql_data_seek() expects parameter 1 to be resource, boolean given in C:\Users\alessandro\Desktop\xampp\htdocs\modifica. php on line 30
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\Users\alessandro\Desktop\xampp\htdocs\modifica. php on line 32
Warning: Invalid argument supplied for foreach() in C:\Users\alessandro\Desktop\xampp\htdocs\modifica. php on line 37
Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in C:\Users\alessandro\Desktop\xampp\htdocs\modifica. php on line 49
il codice è:
<html>
<head>
<title>Modifica di un record</title>
</head>
<body>
<?php
$host = 'localhost';
$database = 'legacalcio';
$user = 'root';
$password = '';
$confirm=$_REQUEST['confirm'];
$cod_giocatore=$_REQUEST['cod_giocatore'];
$db = mysql_connect($host, $user, $password) or die ("impossibile connettersi al server $host");
mysql_select_db($database, $db) or die ("impossibile connettersi al database $database");
if (!$confirm)
{
$query = "select * from giocatori where cod_giocatore=$cod_giocatore";
$dbResult = mysql_query($query, $db);
$AffectedRows = mysql_affected_rows($db);
if($AffectedRows==0)
{
print("<h3> Non esistono record con i criteri selezionati</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>");
print("<td><input type=\"text\" value=\"". $v . "\" name=\"" . $myfield->name . "\" size=\"100\" maxlenght=\"100\"></td></tr>");
}
print("<tr><td colspan=\"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($db);
}
}
else
{
$cod_giocatore=$_REQUEST['cod_giocatore'];
$nome=$_REQUEST['Nome'];
$cognome=$_REQUEST['Cognome'];
$data_nascita=$_REQUEST['Data_Nascita'];
$nazione=$_REQUEST['Nazione'];
$ruolo=$_REQUEST['Ruolo'];
$squadra=$_REQUEST['Squadra'];
$squadra_esordio=$_REQUEST['Squadra_Esordio'];
$data_esordio=$_REQUEST['Data_Esordio'];
$gol_carriera=$_REQUEST['Gol_Carriera'];
$query = "update giocatori set cod_giocatore=\"$cod_giocatore\","
. " nome=\"$nome\","
. " cognome=\"$cognome\","
. " data_nascita=\"$data_nascita\","
. " nazione=\"$nazione\","
. " ruolo=\"$ruolo\","
. " squadra=\"$squadra\","
. " squadra_esordio=\"$squadra_esordio\","
. " data_esordio=\"$data_esordio\""
. " gol_carriera=\"$gol_carriera\""
. " where cod_giocatore=$cod_giocatore";
$dbResult = mysql_query($query, $db);
$AffectedRows = mysql_affected_rows($db);
if ($AffectedRows!=0)
{
print("<h3>Il record è stato aggiornato</h3>");
print("<h3><a href=\"index.php\">Torna alla lista</a></h3>");
}
mysql_close($db);
}
?>
</body>
</html>
Potete aiutarmi?
grazie