Ciao virus, ho rislto creando un pannello di amministrazione dove vengono agginte le email alla news ed eliminate, funziona tutto bene, a parte l'eliminazione di una singola email dalla lista, praticamente mi toglie tutte le email presenti nella tabella news del DB.
nel db tengo la tabella news cosi' (id, nome,cognome, email, data) la tengo cosi perche la uso anche per la registrazione al sito(quindi chi si registra al sito invia i dati in due tabelle registrati e news.
Questo e' il codice della pagina admin per le news
Codice PHP:
<?php
require("config.php");
@mysql_connect($db_server,$db_user,$db_password) or die("Database server connection failed. Check variables \$db_server, \$db_user and \$db_password in config.php");
@mysql_select_db($db_name) or die("Selecting database failed. Check variable \$db_name in config.php");
echo $header;
?>
<h1><?php echo $title; ?> - Amministratore</h1>
<hr>
<?php
$pwd = $_GET["pwd"];
//simple login
if(isset($pwd) && ($pwd == $password)){
$submit = $_POST["submit"];
$submit_newsletter = $_POST["submit_newsletter"];
$del = $_GET["del"];
//insert new address
if(isset($submit)){
$nome = $_POST["nome"];
$email = $_POST["email"];
@mysql_query("INSERT INTO news (email, nome) VALUES ('$email','$nome');");
//errore
if(@mysql_error()){
?>
Inserimento fallito: <?php echo @mysql_error(); ?></p>
[url="javascript:history.back();"]Clicca qui per tornare indietro.[/url]</p><?php
//successo
}else{
?>
Inserita con successo. [url="admin.php?pwd=<?php echo $pwd; ?>"]Clicca per continuare.[/url]</p><?php
}
//elimina
}else if(isset($del)){
@mysql_query("DELETE FROM $news WHERE id=$del;");
//errore
if(@mysql_error()){
?>
Eliminazione non riuscita: <?php echo @mysql_error(); ?></p>
[url="javascript:history.back();"]Clicca qui per tornare indietro.[/url]</p><?php
//successo
}else{
?>
Eliminata con successo. [url="admin.php?pwd=<?php echo $pwd; ?>"]Clicca per continuare.[/url]</p><?php
}
//invia la newsletter
}else if(isset($submit_newsletter)){
$sent = 0;
$result = @mysql_query("SELECT nome,email FROM news ORDER BY email ASC;");
$subject = $_POST["subject"];
$message = $_POST["message"];
?>
Email inviata a ...</p>
<ul><?php
//invia email 1 ad 1
while($row=@mysql_fetch_array($result)){
$nome = $row["nome"];
$email = $row["email"];
?>[*]<?php echo $nome; ?> (<?php echo $email; ?>) ... <?php
if(@mail($email,$subject,$message,"From: $admin <$admin>\n")){
?>sent<?php
$sent++;
}else{
?>failed<?php
}
?><?php
}
?>[/list]
[b]<?php echo $sent; ?>Email inviata.[/b] [url="admin.php?pwd=<?php echo $pwd; ?>"]Clicca qui per continuare.[/url]</p><?php
//print forms
}else{
?><h2>Invia newsletter</h2>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>?pwd=<?php echo $pwd; ?>">
<table>
<tr>
<td>Oggetto:</td>
<td><input type="text" name="subject" class="fixedwidth"></td>
</tr>
<tr>
<td valign="top">Messaggio:</td>
<td><textarea name="message" cols="60" rows="20" class="fixedwidth"><?php echo $signature; ?></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit_newsletter" value="Send"></td>
</tr>
</table>
</form>
<h2>Aggiungi un email</h2>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>?pwd=<?php echo $pwd; ?>" method="post">
<table>
<tr>
<td>Nome:</td>
<td><input type="text" name="nome" value="" maxlength="255"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" value="" maxlength="255"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>
<h2>Indirizzo email</h2>
<table cellpadding="5" cellspacing="2">
<tr class="header">
<td>[b]Nome[/b]</td>
<td>[b]indirizzo email[/b]</td>
<td></td>
</tr>
<?php
$result = @mysql_query("SELECT * FROM news ORDER BY email ASC;");
$colored = false;
while($row=@mysql_fetch_array($result)){
$colored = !$colored;
?><tr<?php if($colored){ ?> class="colored"<?php } ?>>
<td width="200"><?php echo $row["nome"]; ?></td>
<td width="200"><?php echo $row["email"]; ?></td>
<td>[url="<?php echo $_SERVER["]?pwd=<?php echo $pwd; ?>&del=<?php echo $row["id"]; ?>">rimuovi[/url]</td>
</tr><?php
}
?>
</table>
<?php
}
}else{
//print login form
echo $login;
}
//print link to news
?><p align="right">[url="index.php"]Newsletter[/url]</p><?php
//print footer
echo $footer;
//close database connection
@mysql_close();
?>
dopo ti scrivo quello della index