MySQL and PHP Session Variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralph Freshour

    MySQL and PHP Session Variables

    The following 3 mysql/php statements are used in my home page to
    access my admin table:

    $php_linkID = mysql_pconnect( "localhost","us er","pw");
    mysql_select_db ("test_db",$php _linkID);
    $php_resultID = mysql_query("SE LECT * FROM admin", $php_linkID);

    On another web page I try to use another table in the same database
    but I get an error on the if statement - I've saved the $php_linkID as
    a session variable from the home page thinking I can just use it here
    on a different web page - is this not possible?

    $php_resultID = mysql_query("UP DATE controls SET screen_width =
    frm_screen_widt h WHERE id = $php_session_me mber_name, $php_linkID);
    if ($php_resultID != FALSE) <------ errors here
    {
    print "Database update error - Changes not made.";
    }
    else
    {
    print "My Controls successfully updated!";
    }

  • Tom Thackrey

    #2
    Re: MySQL and PHP Session Variables



    On 8-Aug-2003, Ralph Freshour <ralph@primemai l.com> wrote:
    [color=blue]
    > The following 3 mysql/php statements are used in my home page to
    > access my admin table:
    >
    > $php_linkID = mysql_pconnect( "localhost","us er","pw");
    > mysql_select_db ("test_db",$php _linkID);
    > $php_resultID = mysql_query("SE LECT * FROM admin", $php_linkID);
    >
    > On another web page I try to use another table in the same database
    > but I get an error on the if statement - I've saved the $php_linkID as
    > a session variable from the home page thinking I can just use it here
    > on a different web page - is this not possible?
    >
    > $php_resultID = mysql_query("UP DATE controls SET screen_width =
    > frm_screen_widt h WHERE id = $php_session_me mber_name, $php_linkID);
    > if ($php_resultID != FALSE) <------ errors here
    > {
    > print "Database update error - Changes not made.";
    > }
    > else
    > {
    > print "My Controls successfully updated!";
    > }[/color]

    You really should add "or die(mysql_error ())" to each of your mysql_query
    statements.

    I don't know if saving the link as a session variable will work, but it's a
    really bad idea. You could end up with scads of open connections waiting for
    users who will never return.

    You SQL has several problems, like no closing ", missing 's around the
    session id and frm_screen_widt h isn't a variable.
    --
    Tom Thackrey

    Comment

    • R. Rajesh Jeba Anbiah

      #3
      Re: MySQL and PHP Session Variables

      Ralph Freshour <ralph@primemai l.com> wrote in message news:<mo19jv8vv 3vvvvftprb7vira 4cli599toe@4ax. com>...[color=blue]
      > The following 3 mysql/php statements are used in my home page to
      > access my admin table:
      >
      > $php_linkID = mysql_pconnect( "localhost","us er","pw");
      > mysql_select_db ("test_db",$php _linkID);
      > $php_resultID = mysql_query("SE LECT * FROM admin", $php_linkID);
      >
      > On another web page I try to use another table in the same database
      > but I get an error on the if statement - I've saved the $php_linkID as
      > a session variable from the home page thinking I can just use it here
      > on a different web page - is this not possible?[/color]

      Check the variable by echoing the content.... BTW, storing the
      link id in session is not a good practice. Session may expire and will
      throw errors.

      ---
      Email: rrjanbiah-Y!com

      Comment

      • Andy Hassall

        #4
        Re: MySQL and PHP Session Variables

        On Sat, 09 Aug 2003 05:34:04 GMT, Ralph Freshour <ralph@primemai l.com> wrote:
        [color=blue]
        >The following 3 mysql/php statements are used in my home page to
        >access my admin table:
        >
        >$php_linkID = mysql_pconnect( "localhost","us er","pw");
        >mysql_select_d b("test_db",$ph p_linkID);
        >$php_resultI D = mysql_query("SE LECT * FROM admin", $php_linkID);
        >
        >On another web page I try to use another table in the same database
        >but I get an error on the if statement - I've saved the $php_linkID as
        >a session variable from the home page thinking I can just use it here
        >on a different web page - is this not possible?[/color]

        No, you can't do that. A link ID is a resource handle, which is no longer
        valid past the end of the script.

        Besides, the whole idea of persistent connections is that opening up a
        connection with mysql_pconnect on subsequence requests is cheap as it comes out
        of a pool of already opened connections.
        [color=blue]
        >$php_resultI D = mysql_query("UP DATE controls SET screen_width =
        >frm_screen_wid th WHERE id = $php_session_me mber_name, $php_linkID);
        >if ($php_resultID != FALSE) <------ errors here
        > {
        > print "Database update error - Changes not made.";[/color]

        You've got the checking reversed as well; it's FALSE for an error.

        --
        Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
        Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

        Comment

        Working...