943,646 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 443
  • PHP RSS
May 5th, 2009
0

Delete function acts unexpectedly

Expand Post »
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

PHP Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 10
Solved Threads: 0
Light Poster
JimD C++ Newb is offline Offline
46 posts
since Oct 2008
May 5th, 2009
0

Re: Delete function acts unexpectedly

what you have written in delete_user.php file...
And your div tag is not closed properly..
Post delete_user.php file data..
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
May 5th, 2009
0

Re: Delete function acts unexpectedly

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?
Reputation Points: 10
Solved Threads: 0
Light Poster
JimD C++ Newb is offline Offline
46 posts
since Oct 2008
May 5th, 2009
0

Re: Delete function acts unexpectedly

see here , you have started a div like this :
PHP Syntax (Toggle Plain Text)
  1. <body>
  2. <form action="delete_user.php" method ="post">
  3. <div id="main">
But You have to Ends it like
PHP Syntax (Toggle Plain Text)
  1. </div></form></body>
Instead of
PHP Syntax (Toggle Plain Text)
  1. </form>
  2. </body>
  3. </div>
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
May 5th, 2009
0

Re: Delete function acts unexpectedly

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
Reputation Points: 10
Solved Threads: 0
Light Poster
JimD C++ Newb is offline Offline
46 posts
since Oct 2008
May 5th, 2009
0

Re: Delete function acts unexpectedly

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.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: MySQL Question ...
Next Thread in PHP Forum Timeline: Wanted Help ,urgently with PHP and Ajax





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC