Jump to content

[SOLVED] problem deleting SQL record with php


sempreexe

Recommended Posts

I'm trying to delete 1 SQL record with a confirmation page and on confirmation send me to a specified page.

 

The record deletes on clicking the yes button for confirmation but I still get the confirmation buttons in the next window, is there a possibility so I get to a specified webpage instead?

 

The image is when I confirmed to delete

 

[attachment deleted by admin]

and here is my missing code of course:

 

<?php

$host="localhost";

$username="root";

$password="***";

$fout="ERROR";

$dbnaam="nieuws";

$db=mysql_connect($host, $username, $password) or die (mysql_error());

mysql_select_db($dbnaam, $db) or die (mysql_error());

if (isset($_POST['bevestiging']))

{

$query="DELETE FROM nieuwsitems WHERE ID=".$_POST['ID'];

$result=mysql_query($query,$db)or die($fout);

echo ("Dit is uitgevoerd $query");

if($result)

{

echo ("ID= ".$_POST['ID']."is verwijderd");

}

}

else

{

$query="SELECT * FROM nieuwsitems WHERE ID=".$_GET["ID"];

$result=mysql_query($query,$db) or die($fout);

}

?>

<html>

<body>

<?php

while ($rij=mysql_fetch_array($result))

{

echo("ID = " . $rij['ID'] . "<br>\n");

echo("Nieuws = ". $rij['nieuws'] ."<br>\n");

echo("Datum = ". $rij['datum'] . "<br><br>\n");

}?>

Ben je zeker dat deze nieuwsitem verwijderd mag worden?<br>

<form action="<?php echo($_SERVER["PHP_SELF"]);?>" method="post">

<input type="hidden" name="bevestiging" value="1">

<input type="hidden" name="ID" value="<?php echo($_GET["ID"]);?>">

<input type="Submit" value="Ja">

<input type="Button" value="Nee" onclick="javascript:history.back();">

</form>

</body>

</html>

i don't understand the language you are using but it looks to me like you are trying to fetch the array of a DELETE FROM query which is impossible because DELETE query's return nothing

 

you need to remove the else on line 19 so a SELECT query is done every time.

 

Scott

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.