Hello!

I have a small problem with a MySQL query inside a PHP site. If a user clicks "Yes" to delete a record, the record should be deleted (which works great)

However, when the user clicks "No", it should redirect the user to another location, leaving the record intact...but it redirects the user AND deletes the record anyway.

What am I overlooking?

Thank you in advance for any assistance!!

- Jim

require_once('mysql_connect.php');
if(isset($_POST['submitted'])){
if($_POST['sure'] == "Yes") {
	echo $_POST['submitted'];
	$query = "delete from movie_users where movie_users_id = '$id'";
	$result = @mysql_query ($query);
	header("Location: current_users.php");
	echo "User deleted successfully";
} elseif($_POST['sure'] == "No") {
        header("Location: not_deleted.php");
}
}
		
	?>
	<body>
	<form action="delete_user.php" method ="post">
	<div id="main">
	<p><?PHP echo "Are you sure you want to delete user $fl_name"; ?>	
	</p>
	<input type = "radio" name = "sure" value = "Yes" /> Yes
	<input type = "radio" name = "sure" value = "No" /> No</p>
	<p><input type = "submit" name = "submit" value = "submit" /> </p>
	<input type = "hidden" name = "submitted" value = "TRUE" />
	<input type = "hidden" name = "id" value = "<?php echo $id; ?>" />
	</form>
	</body>
	</div>
 
mysql_close();
<?php
include('footer.php');

?>

Recommended Answers

All 5 Replies

what you have written in delete_user.php file...
And your div tag is not closed properly..
Post delete_user.php file data..

Oh! I found the error myself! /smackhead

<form action="delete_user.php" method ="post">

needed to be

<form action="delete_user1.php" method ="post">

I forgot that I had changed the name of the file to do some other work on it while keeping the integrity of the first file incase the changes didn't work.

Thank you!

But what is wrong with my close tag?

see here , you have started a div like this :

<body>
	<form action="delete_user.php" method ="post">
	<div id="main">

But You have to Ends it like

</div></form></body>

Instead of

</form>
	</body>
	</div>

Thank you for pointing out the error I didn't even see.

Everything seemed to work properly the way that I had it before, so I guess my question is...is it just good practice to close them in the reverse order you opened them, or does it really make a difference that just didn't happen to appear in this particular instance?

Thank you again

- Jim

Thank you for pointing out the error I didn't even see.

Everything seemed to work properly the way that I had it before, so I guess my question is...is it just good practice to close them in the reverse order you opened them, or does it really make a difference that just didn't happen to appear in this particular instance?

Thank you again

- Jim

It's not that it's "good practice." That's the right way to do it, it's like asking if you should put semicolons at the end of your line. It's how HTML/XML works.

<tagopen><innertag>blah blah</innertag></tagopen> = TagOpen CONTAINS innertag CONTAINS text

NOT

<tagopen><innertag>blah blah</tagopen></innertag> = TagOpen CONTAINS START innertag CONTAINS text, END TagOpen

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.