Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: can i do this?

  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy can i do this?

    hi all,
    hello, u see, i am trying to check the username with the session...like this

    PHP Code:
    $sql "SELECT * from tblgallery username = " .$_SESSION["userID"];
                
    $rs mysql_query($sql);
                
    $nRows mysql_num_rows($rs); 
    but i am getting this notice :

    Notice: Undefined variable: _SESSION in c:\program files\apache group\apache\htdocs\ewedding\photoupload.php on line 199
    coz i will be needing the username to insert into the database. so can i insert it like this?

    PHP Code:
    "INSERT INTO tblgallery (username) VALUES ('" $_SESSION["userID"] . "'); 
    i am not too sure about sessions...pls some one help...thank you so much
    Warm Regards,
    Mivec

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please choose a meaningfull title.

    About the message --> it's a notice, not an error. Run a search for errorreporting for more info and possible fixes.
    About your actual task, is 'username' a string or numerical varaible ?
    $sql = "SELECT * from tblgallery username = " .$_SESSION['userID'];
    is just fine if it's a numerical column, else it's
    $sql = "SELECT * from tblgallery username = '" .$_SESSION['userID'] . "'";
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mivec
    hi all,
    hello, u see, i am trying to check the username with the session...like this

    PHP Code:
    $sql "SELECT * from tblgallery username = " .$_SESSION["userID"];
                
    $rs mysql_query($sql);
                
    $nRows mysql_num_rows($rs); 
    but i am getting this notice :
    A notice usually tells you that a variable is undefined bwfore you use it. So make sure that the variable in question is defined. PHP is set to default to show notices even tho many hosts disable this feature.

  • #4
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    844
    Thanks
    15
    Thanked 9 Times in 9 Posts
    It would be easier to do something like this...
    PHP Code:
    $user=$_SESSION["userID"]

     
    $sql "SELECT * from tblgallery username='.$user.'" 
                
    $rs mysql_query($sql); 
                
    $nRows mysql_num_rows($rs); 
    and your insert method would be:
    PHP Code:
    "INSERT INTO tblgallery (username) VALUES ('$user')"

    Also as raf said make sure that there is something in the session variable...
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by dniwebdesign
    It would be easier to do something like this...
    PHP Code:
    $user=$_SESSION["userID"]

     
    $sql "SELECT * from tblgallery username='.$user.'" 
                
    $rs mysql_query($sql); 
                
    $nRows mysql_num_rows($rs); 
    No. Your $sql line would throw 2 error.

    it's either
    PHP Code:
    $sql "SELECT * from tblgallery WHERE username='$user'"
    //or 
    $sql "SELECT * from tblgallery WHERE username='" $user "'";
    //or 
    $sql 'SELECT * from tblgallery WHERE username=\''.$user.'\''
    I prefere the second one because it's better readable and i always concatenate strings and variables (i never just include the variables). The first version would be my second choice.
    The third one will probably be executed slightly faster (no unnescecary parsing no the sql-statement) but it's harder to read and not as portable (if you need to testrun it somewhere).
    sql-statements and eval'd code are about the only strings where i use double quotes.
    Last edited by raf; 04-13-2004 at 07:03 PM. Reason: edit php-tags so you can see the coloucoding. Editbis : added the WHERE
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #6
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    844
    Thanks
    15
    Thanked 9 Times in 9 Posts
    oh, dang... forgot the double quotes...
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #7
    Regular Coder
    Join Date
    Mar 2004
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts
    am i mistaken

    dont you need a WHERE clause

    PHP Code:
    $sql "SELECT * from tblgallery WHERE username='" $user "'"

  • #8
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    indeed.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #9
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    844
    Thanks
    15
    Thanked 9 Times in 9 Posts
    yea, I was thinking that too but I a$sumed Raf knew what he was doing and he didn't use it.... so much for assuming..
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #10
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by dniwebdesign
    yea, I was thinking that too but I a$sumed Raf knew what he was doing and he didn't use it.... so much for assuming..
    i didn't realy read it. just copy and pased it
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

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