brown2005 Posted February 8, 2013 Share Posted February 8, 2013 (edited) global $db; $confirmcode = $_GET['code']; $stmt = $db->prepare("SELECT * FROM people_emails WHERE people_emails_valid= :valid"); $stmt->execute(array(':confirm' => $confirmcode)); $rows = $stmt->fetch(PDO::FETCH_ASSOC); return true; what is wrong with the above? it works in one function but not another? yet the function works wihen i remove $stmt = $db->prepare("SELECT * FROM people_emails WHERE people_emails_valid= :valid"); $stmt->execute(array(':confirm' => $confirmcode)); $rows = $stmt->fetch(PDO::FETCH_ASSOC); Edited February 8, 2013 by brown2005 Quote Link to comment https://forums.phpfreaks.com/topic/274230-code-works-in-one-function-but-not-other/ Share on other sites More sharing options...
trq Posted February 8, 2013 Share Posted February 8, 2013 Firstly, using the global keyword and the global variable $_GET in a function is terrible. Functions are meant to encapsulate code, doing so completely breaks that concept. Secondly, when asking for help on a help forum, it is best to post all relevant code. Can you post the actual functions in questions? Quote Link to comment https://forums.phpfreaks.com/topic/274230-code-works-in-one-function-but-not-other/#findComment-1411143 Share on other sites More sharing options...
Barand Posted February 8, 2013 Share Posted February 8, 2013 So you are saying that this function works function myfunc() { global $db; $confirmcode = $_GET['code']; return true; } Quote Link to comment https://forums.phpfreaks.com/topic/274230-code-works-in-one-function-but-not-other/#findComment-1411144 Share on other sites More sharing options...
SofWare Posted February 8, 2013 Share Posted February 8, 2013 So you are saying that this function works function myfunc() { global $db; $confirmcode = $_GET['code']; return true; } myfunc() would return true and $db and $_GET['code'] are the global variables. I agree with trq that all the code (e.g. creating the global variable $db) needs to be posted. Quote Link to comment https://forums.phpfreaks.com/topic/274230-code-works-in-one-function-but-not-other/#findComment-1411168 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.