Jeevan25 Posted April 10, 2007 Share Posted April 10, 2007 I have two functions. One is delete_part($part_id) which deletes a video clip with the passed id from mysql db. The other one is delete_report($part_id). This one deletes a report with the given id from the mysql db. Both $part_id are same. Here are the functions. function delete_part($part_id) { global $link, $page_name, $_GET; if ($part_id < 1) { display_header(); echo ("Error"); display_footer(); } display_header(); $sql = 'DELETE FROM parts WHERE part_id = ' . $part_id; $result = mysql_query($sql,$link); if ($result) { echo ("<br /><br /><b>Successfully deleted</b>"); } else echo ("Error: " . mysql_error()); display_footer();} function delete_report ($part_id) { global $link,$db,$_GET,$_POST,$page_name; display_header(); if ($part_id < 1) { echo ("Invalid report!"); display_footer(); } $sql = "DELETE FROM report WHERE report_part = " . $part_id; $result = mysql_query($sql,$link); if (!result) { echo ("Error with deleting report: " . mysql_error()); display_footer(); } else $result; echo ("Report successfully deleted."); display_footer();} Both work fine when called separately. But when I call them at the same time, the first function to be called work but the second one doesn't work. I tried placing both in different orders but only first one works. Anyone know why? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 10, 2007 Share Posted April 10, 2007 It might be because you are defining $_GET and $_POST as globals. You don't need to do that, they are referred to as superglobals, and are automatically global in any scope. Explicitly declaring one as global may mess it up. If you try that and it doesn't fix the problem, say what specifically the second function is doing, not that it just doesn't work. Not that this matters for the problem, but you will also want to terminate the function under certain conditions, like this one: if ($part_id < 1) { display_header(); echo ("Error"); display_footer();} You wouldn't want the function to continue after that because the next statement prints the header again (which was already printed), so include a return statement to stop the function from continuing. if ($part_id < 1) { display_header(); echo ("Error"); display_footer(); return;} Link to comment Share on other sites More sharing options...
Jeevan25 Posted April 11, 2007 Author Share Posted April 11, 2007 Whenever display_footer() is called, the script is terminated because it contains a exit() command at the end. Therefore I don't have to manually do anything else. I tried removing the form vars, but still no luck. I still have no clue why. Two different tables, and nothing in common except the id.Ohh quick edit:Nevermind. Thanks for you help. Just posting that reminded me that in both functions display_footer terminates script so thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now