954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Delete function acts unexpectedly

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');

?>
JimD C++ Newb
Light Poster
46 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

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

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

Oh! I found the error myself! /smackhead

needed to be

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?

JimD C++ Newb
Light Poster
46 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

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>
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

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

JimD C++ Newb
Light Poster
46 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

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.

blah blah = TagOpen CONTAINS innertag CONTAINS text

NOT

blah blah = TagOpen CONTAINS START innertag CONTAINS text, END TagOpen

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You