Salve, ho un problema con l'eliminazione dei record in una table mysql: vi posto il codice interessato:
codice:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html>
<head>
<script language=javascript>
function elimina(codice)
{
f.cod.value=cod;
f.action="del_usr.php";
f.submit();
}
function inserisci(c)
{
f.cod.value=c;
f.action="ins_usr.php";
f.submit();
}
</script>
<link href=stili.css type=text/css rel=stylesheet></link>
<title>entrata</title>
</head>
<body class=body>
<p class=titolo>TITOLO</p><hr></hr>
<?php
$host="localhost";
$username="root";
$password="";
$database="vetture";
$conn=mysql_connect($host,$username,$password);
mysql_select_db($database) or die("Impossibile selezionare il database");
if($_POST && isset($_GET['id']))
{aggiorna_record();}
elseif(isset($_GET['id']))
{mostra_record();}
else
mostra_lista();
function mostra_lista()
{
if(isset($_GET['msg']))
echo ''.htmlentities($_GET['msg']).'
';
$query = "SELECT id, uid, upwd FROM members";
$result = mysql_query($query);
if (!$result) {
die("Errore nella query $query: " . mysql_error());
}
echo '
<div align=center valign=center><table border="1">
<tr>
<th>id</th>
<th>utente</th>
<th>password</th>
<th></th>
</tr>';
while ($row = mysql_fetch_assoc($result))
{
$id=htmlspecialchars($row['id']);
$uid=htmlspecialchars($row['uid']);
$upwd=htmlspecialchars($row['upwd']);
$link = $_SERVER['PHP_SELF'] . '?id=' . $row['id'];
echo "<form action=\"del_usr.php\" name=f method=post><tr>
<td>$id</td>
<td>$uid</td>
<td>$upwd</td>
<td><a href=\"$link\">modifica</a></td>
<td><input type=button value=elimina onclick=elimina('$riga[id]')></input></td>
</tr></form>";
}
echo '</table></div>';
mysql_free_result($result);
mysql_close();
}
function mostra_record()
{
$id = intval($_GET['id']);
$query = "SELECT id,uid,upwd FROM members WHERE id = $id";
$result = mysql_query($query);
if (!$result)
{ die("Errore nella query $query: " . mysql_error()); }
if(mysql_num_rows($result) != 1)
{ die("l'ID passato via GET è errato"); }
list($id,$uid,$upwd)=mysql_fetch_row($result);
$id=htmlspecialchars($id);
$uid=htmlspecialchars($uid);
$upwd=htmlspecialchars($upwd);
echo "
<table border=1>
<form action=\"upr.php?id=$id\" method=\"post\">
<tr><td>utente:</td><td>
<input name='utente' type='text' value=\"$uid\"/></td></tr>
<tr><td>password:</td><td>
<input name='password' type='text' value=\"$upwd\"/></td>
<td><input name='invia' type='submit' value='Invia'/></td></tr>
</form></table>
";
}
?>
<hr></hr>
<form action="ins_usr.php" method="post">
<table width='20%' align='center' border='1' colspan='2' bgcolor='#000000'>
<td style='font size:14pt'>USER</td>
<td style='font size:14pt'><input type='text' name='uid' size=50 maxlength=7 alt='uid' align='left'</td><tr>
<td style='font size:14pt'>PASSWORD</td>
<td style='font size:14pt'><input type='text' name='upwd' size=50 maxlength=16 alt='upwd' align='left'</td><tr>
<td align=center><input type="submit" value="Inserisci" onclick="inserisci()"></td>
</table>
</form>
<hr></hr>
<div align="center">
<table width="5%" align="center" border="1" cellpadding="1" cellspacing="0" bgcolor='#000000'>
<form action=login_success.php>
<input type="submit" value="Torna al Menu">
</td>
</form>
</table>
</body>
</html>
</html>
e questo è lo script di eliminazione del_usr.php:
codice:
header("location:usr_mgr.php");
<html>
<head>
</head>
<body>
Record Eliminato Correttamente!
<?php
$codice=$_POST["cod"];
$conn=mysql_connect("127.0.0.1","root","");
mysql_select_db("vetture");
$sql="delete from members where id='$codice'";
mysql_query($sql);
mysql_close($conn);
?>
</body>
</html>
Il problema riscontrato con internet explorer è il seguente:
Dettagli errore pagina Web
Agente utente: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.3; Creative AutoUpdate v1.10.10)
Timestamp: Sat, 29 Jan 2011 13:15:15 UTC
Messaggio: 'f.cod' is null or not an object
Linea: 7
Carattere: 8
Codice: 0
URI:
http://127.0.0.1/upd.php
In pratica quando premo sul button Elimina non mi cancella il record.. cosa c'è di sbagliato?
Confido in una vostra risposta!!