SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    United Kingdom
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Hellllllllllllp !!!! Please

    Sorry for all the questions, I am new to PHP and still trying to learn..

    Thanks for the help in my last post, "problems with variables" I have changed the register_globals to be on, just as a test and that worked. I was unable to post a reply in that thread for some reason :-( It was moved and said I did not have permission to add to it..


    I have a new problem, even though I have made register_globals=on I am STILL getting problems with some variables. I saw some code to display the databases available from mySQL and it all seems to work (i.e it is displaying the databases) however, even though it is working, there is an error saying the variables are not defined. and I am now really confused.

    I am new to PHP so dont really know how to troubleshoot this.


    This is the output

    Notice: Undefined variable: db_list in c:\web\list-dbs.php on line 14

    barc
    gb_data
    mysql
    phpbb

    so it does actually display the databases, but has an error.. Here is the script:


    <?php

    $conn = @mysql_connect("localhost","root","" )
    or die("Sorry - could not connect to MySQL" );



    $rs2= @mysql_list_dbs($conn)
    or die("Sorry - could not list databases" );

    #create a list of all the databases
    for($row=0; $row < mysql_num_rows($rs2); $row++)
    {
    $db_list .= mysql_tablename($rs2, $row)."<br>";

    }


    ?>

    <html><head><title>Listing databases</title></head>
    <body><h3><?php echo($db_list); ?> </h3></body></html>


    It is all in a file called listdb.php which I call from http://localhost/listdb.php

  2. #2
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just instantiate the variable before adding to it

    $db_list = '';
    while(.......)
    {
    $db_list .=

    your error just tells you that $db_list doesn't exist before you try using it - in one line you could...

    $db_list = (isset($db_list)) ? mysql_tablename($rs2, $row)."<br>" : $db_list.mysql_tablename($rs2, $row)."<br>";

    though that's more coding than just instantiating it before the call.
    teckis - that's news to me.

  3. #3
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try to declare the variable before the for loop.
    PHP Code:
    #create a list of all the databases
    $db_list '';
    for(
    $row=0$row mysql_num_rows($rs2); $row++)
    {
        
    $db_list .= mysql_tablename($rs2$row)."<br>"

    HTH

    -Helge

  4. #4
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Threads merged. Please do not post multiple copies of the same thread

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    United Kingdom
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops sorry for posting multiple copies of the same thread, did not realise.
    :-)

  6. #6
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WHO told you switch globals on ?

    This is utter crap - even on a localhost machine for testing only. 8(

    No bloody wonder so many beginners have problems - you'd better switch globals to OFF and from now on use PHP properly:

    $_GET and $_POST and $_SESSION and $_COOKIE for your URL and FORM variables, sessions etc.

    Some people eh ?

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    United Kingdom
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No one told me to change it. I just did it, found on the web somewhere . 'sides, I did not really know the implications of it.

  8. #8
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  9. #9
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll find a lot of usefull tips & tricks right here

    You'll also read about register_globals etc...


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
  •