Jump to content

code works in one function but not other?


brown2005

Recommended Posts

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);

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.