gabs Posted May 17, 2012 Share Posted May 17, 2012 Hi I have a table class and functions I want to call in another function but can't get it working. Some help will be very welcome. It seesm that the new table class is not working in this function if I pass the values to it, I have tested the class, it does get the post values I post to it so $_POST['id'] are being received as well as all the other $_POST's but the table class and find function is not working, it works fine if I don't put it in a function.. function edit() { if (isset($error)){ $error.="Please fix the error(s) above";} else { if ($_POST['id'] <> "") { $update =& new table($db, 'publisher'); $update->find($_POST['id']); $update->name = $_POST['name']; $update->url = $_POST['url']; $update->contact = $_POST['contact']; $update->address = $_POST['address']; $update->phone = $_POST['phone']; $update->email = $_POST['email']; $update->save(); $error = "The Publisher has been edited"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/262676-call-a-class-and-function-in-another-function/ Share on other sites More sharing options...
requinix Posted May 17, 2012 Share Posted May 17, 2012 if (isset($error)){ Where is $error coming from? If you're about to say "outside the function" then let me reply preemptively with a "functions can't access variables defined outside of them" and how one solution is to have the function return the message. Quote Link to comment https://forums.phpfreaks.com/topic/262676-call-a-class-and-function-in-another-function/#findComment-1346359 Share on other sites More sharing options...
gabs Posted May 17, 2012 Author Share Posted May 17, 2012 no error showing, but wound the answer.. class sitefunctions extends table { function edit_publisher($db) { if (isset($error)){ $error.="Please fix the error(s) above";} else { if ($_POST['id'] <> "") { $update =& new table($db, 'publisher'); $update->find($_POST['id']); $update->name = $_POST['name']; $update->url = $_POST['url']; $update->contact = $_POST['contact']; $update->address = $_POST['address']; $update->phone = $_POST['phone']; $update->email = $_POST['email']; $update->save(); $error = "The Publisher has been edited"; } } } } Quote Link to comment https://forums.phpfreaks.com/topic/262676-call-a-class-and-function-in-another-function/#findComment-1346361 Share on other sites More sharing options...
requinix Posted May 17, 2012 Share Posted May 17, 2012 ...Is there any meaning behind posting the code again? Quote Link to comment https://forums.phpfreaks.com/topic/262676-call-a-class-and-function-in-another-function/#findComment-1346375 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.