How can I echo a custom field?

Discussion in 'aMember Pro v.4' started by comptech520, Nov 10, 2011.

  1. comptech520

    comptech520 New Member

    Joined:
    Oct 5, 2007
    Messages:
    28
    How can I echo the value of a custom field?
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Where?
  3. comptech520

    comptech520 New Member

    Joined:
    Oct 5, 2007
    Messages:
    28
    On a custom PHP page.
  4. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    If you was able to take User object, you may access custom fields like that

    $user->data()->get('my_not_sql_field');
    $user->data()->set('my_not_sql_field', 'xxx')->update(); // update needs to be called once for entire record
    or
    $user->my_sql_field = 1;
    $user->update();
  5. comptech520

    comptech520 New Member

    Joined:
    Oct 5, 2007
    Messages:
    28
    What code do I need to add so it can pull this data from the database? Something similar to the php include method in v3?
  6. comptech520

    comptech520 New Member

    Joined:
    Oct 5, 2007
    Messages:
    28
    I created a page with this content, what do I need to add to link this to aMember?

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test Index</title>
    </head>

    <body>
    <?php
    $user->my_sql_field = 1;
    $user->update();?>
    </body>
    </html>
  7. primitive_soul

    primitive_soul New Member

    Joined:
    Oct 11, 2010
    Messages:
    14
    So if I have a custom field called 'rewards' (not sql) and I am keeping a CSV list in it, how would I update it? Like this?
    $newreward = "20% off";
    $currentrewards = $user->data()->get('rewards');
    $newlist = $currentrewards.$newreward.",";
    $user->data()->set('rewards', $newlist)->update();
  8. primitive_soul

    primitive_soul New Member

    Joined:
    Oct 11, 2010
    Messages:
    14
    So I tried that and it threw me an error:

    Here's my whole code. line 16 is the "$currentrewards = $user->data()->get('rewards');" below.

    PHP:
    <?php
    include '../members/bootstrap.php';
    if (isset(
    $_POST["submit"])) {
    $name $_POST["nm"];
    $cost $_POST["cst"];
    $balance Am_Di::getInstance()->plugins_misc->loadGet('points')->balance();
    $xml simplexml_load_file('../rewards.xml');
    $avail;
    foreach (
    $xml->reward as $reward){
    if(
    $reward['name'] == $name){
    $avail $reward->avail;
    }
    }
    if (
    $cost <= $balance){
    Am_Di::getInstance()->plugins_misc->loadGet('points')->debit($cost$name);
    $currentrewards $user->data()->get('rewards');
    $newlist $currentrewards.$name.",";
    $user->data()->set('rewards'$newlist)->update();
    header'Location: http://www.primitivesoultattoo.com/members/Artists-Page',TRUE,303 );
    }else{
    header'Location: http://www.primitivesoultattoo.com/members/Artists-Page',TRUE,303 );
    }
    }
    ?>
  9. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    You didn't initialize $user variable in your code.
    If you need to update user who is logged in currently:
    PHP:
    $user Am_Di::getInstance()->authUser->getUser();
    if(
    $user){
     
    $rewards $user->data()->get('rewards');
    // etc... 

    }
  10. primitive_soul

    primitive_soul New Member

    Joined:
    Oct 11, 2010
    Messages:
    14
    That's exactly what I've been looking for in the documentation. Thank you, sir!!!
  11. primitive_soul

    primitive_soul New Member

    Joined:
    Oct 11, 2010
    Messages:
    14
    So I initialized the user as you said and got:
    I used an echo statment to see where it was getting hung up exactly and it is the
    Does it matter that this file is located outside of the main amember folder? It's in a folder on the same site but in another folder other than the amember folder.
  12. admirable

    admirable New Member

    Joined:
    Oct 9, 2012
    Messages:
    1
    I am having the same issue right now. Was there an answer for this?

Share This Page