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

Edited by brown2005
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.