Jump to content

[SOLVED] Help with a function (or something) to delete sql stuff


felipeebs

Recommended Posts

Hi!

 

I'm trying to make a function, or something like that,  to delete a row from a mysql table

The script that show the stuff runs OK

now... I don't know how to make a link and the function to delete

 

here is my FULL script:

 

<?php header("Content-Type: text/html; charset=ISO-8859-1",true) ?>
<?php
$admin = $_GET['admin'];
$conexao = mysql_connect("localhost","root","schmitz");
mysql_select_db("felipeebs");
if(isset($admin) && $admin == "password") {
// Counter script BEGIN
$quant = mysql_query("SELECT * FROM newsletter");
$conta = mysql_num_rows($quant);
echo "<p>Registered e-mails: " . $conta . "</p>";
// Counter script END
$sql = "SELECT * FROM newsletter order by nome";
$query = mysql_query($sql);
echo "<table>";
while($lista = mysql_fetch_array($query))
{
	echo "<tr><td style=\"width:150px; border:solid 1px #000;\">" . $lista["nome"] . "</td><td style=\"width:300px; border:solid 1px #000;\">" . $lista["email"] . "</td><td><a href=\"verif.php?admin=" . $admin . "&del=" . $lista["email"] . "\">Remove</a></td></tr>";
}
echo "</table>";
} 
else {
echo "Only admins allowed...";
}
?>

 

inside the while I've inserted the stuff i want (if possible): &del=" . $lista["email"] . " in the "remove" link

 

If anyone can help ;)

try passing an action aswell, eg:

 

	echo "<tr><td style=\"width:150px; border:solid 1px #000;\">" . $lista["nome"] . "</td><td style=\"width:300px; border:solid 1px #000;\">" . $lista["email"] . "</td><td><a href=\"verif.php?act=del&admin=" . $admin . "&del=" . $lista["email"] . "\">Remove</a></td></tr>";

 

Then, in verif.php as either an if statement or a switch to determine the action

Let me try...

 

The if:

if(isset($del) && $act == "del") {
$sql = "DELETE FROM `newsletter` WHERE CONVERT(`newsletter`.`email` USING utf8) = '$del'";
$query = mysql_query($sql);
echo "deled";
}

 

Thelink stuff:

echo "<tr><td style=\"width:150px; border:solid 1px #000;\">" . $lista["nome"] . "</td><td style=\"width:300px; border:solid 1px #000;\">" . $lista["email"] . "</td><td><a href=\"verif.php?admin=" . $admin . "&act=del&del=" . $lista["email"] . "\">Remover</a></td></tr>";

 

and the result:

THANK YOU :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.