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]

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.