Delete function acts unexpectedly

Reply

Join Date: Oct 2008
Posts: 40
Reputation: JimD C++ Newb is an unknown quantity at this point 
Solved Threads: 0
JimD C++ Newb JimD C++ Newb is offline Offline
Light Poster

Delete function acts unexpectedly

 
0
  #1
May 5th, 2009
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

  1. require_once('mysql_connect.php');
  2. if(isset($_POST['submitted'])){
  3. if($_POST['sure'] == "Yes") {
  4. echo $_POST['submitted'];
  5. $query = "delete from movie_users where movie_users_id = '$id'";
  6. $result = @mysql_query ($query);
  7. header("Location: current_users.php");
  8. echo "User deleted successfully";
  9. } elseif($_POST['sure'] == "No") {
  10. header("Location: not_deleted.php");
  11. }
  12. }
  13.  
  14. ?>
  15. <body>
  16. <form action="delete_user.php" method ="post">
  17. <div id="main">
  18. <p><?PHP echo "Are you sure you want to delete user $fl_name"; ?>
  19. </p>
  20. <input type = "radio" name = "sure" value = "Yes" /> Yes
  21. <input type = "radio" name = "sure" value = "No" /> No</p>
  22. <p><input type = "submit" name = "submit" value = "submit" /> </p>
  23. <input type = "hidden" name = "submitted" value = "TRUE" />
  24. <input type = "hidden" name = "id" value = "<?php echo $id; ?>" />
  25. </form>
  26. </body>
  27. </div>
  28.  
  29. mysql_close();
  30. <?php
  31. include('footer.php');
  32.  
  33. ?>
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,072
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: Delete function acts unexpectedly

 
0
  #2
May 5th, 2009
what you have written in delete_user.php file...
And your div tag is not closed properly..
Post delete_user.php file data..
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 40
Reputation: JimD C++ Newb is an unknown quantity at this point 
Solved Threads: 0
JimD C++ Newb JimD C++ Newb is offline Offline
Light Poster

Re: Delete function acts unexpectedly

 
0
  #3
May 5th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,072
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: Delete function acts unexpectedly

 
0
  #4
May 5th, 2009
see here , you have started a div like this :
  1. <body>
  2. <form action="delete_user.php" method ="post">
  3. <div id="main">
But You have to Ends it like
  1. </div></form></body>
Instead of
  1. </form>
  2. </body>
  3. </div>
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 40
Reputation: JimD C++ Newb is an unknown quantity at this point 
Solved Threads: 0
JimD C++ Newb JimD C++ Newb is offline Offline
Light Poster

Re: Delete function acts unexpectedly

 
0
  #5
May 5th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Delete function acts unexpectedly

 
0
  #6
May 5th, 2009
Originally Posted by JimD C++ Newb View Post
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
Last edited by ShawnCplus; May 5th, 2009 at 12:02 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC