SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2002
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    global variables

    Okay, so Im using this defined variable inside a php script (using postgres DB):

    $link = pg_connect("host=localhost user=sl26 password=mypass");

    and am trying to call the variable from within a function like this:

    function register( $userLog, $FirstName, $LastName, $pWord, &$dberror ) {

    if (! (global $link) ) {
    $dberror = "Couldn't connect to postgres server";
    return false;
    }
    $query = "INSERT INTO staff VALUES('$userLog','$FirstName','$LastName','$pWord')";
    if ( ! pg_query(global $link, $query) ) {
    $dberror = "Couldn't insert values to DB!";
    return false;
    }
    return true;
    }

    Why won't it work! For now, I'm defining various $links within each function but this is wastful right? Whats the answer...I thought you could access the variable using the global keyword! Ahh!

    Thanks in advance for your help.

  2. #2
    SitePoint Zealot Alarion's Avatar
    Join Date
    May 2001
    Location
    Virginia
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try:

    if (!$GLOBALS[link]) {

    instead
    -=Alarion=-
    Protollix - Linux hosting from $3.95/m


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •