SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Member powerstation79's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hello, i need some guidance


    Hi, let me introduce myself, my name is David Lee, i just begin to learn php & mysql. But, unfortunately, i can't retrieve data from mysql and publish on the browser. The following codes is i copied from the sitepoint books. Can anybody give me some advice on this matter.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Our List of Jokes</title>
    <meta http-equiv="content-type"
    content="text/html; charset=iso-8859-1" />
    </head>
    <body>
    <?php
    // Connect to the database server
    $dbcnx = @mysql_connect('localhost', 'root', 'fun');
    if (!$dbcnx) {
    exit('<p>Unable to connect to the ' .
    'database server at this time.</p>');
    }
    // Select the jokes database
    if (!@mysql_select_db('ijdb')) {
    exit('<p>Unable to locate the joke ' .
    'database at this time.</p>');
    }
    ?>
    <p>Here are all the jokes in our database/p>
    <blockquote>
    <?php
    // Request the text of all the jokes
    $result = @mysql_query('SELECT joketext FROM joke');
    if (!$result) {
    exit('<p>Error performing query: ' . mysql_error() . '</p>');
    }
    // Display the text of each joke in a paragraph
    while ($row = mysql_fetch_array($result)) {
    echo '<p>' . $row['joketext'] . '</p>';
    }
    ?>
    </blockquote>
    </body>
    </html>

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, Welcome to the forums When u say "can't" do u mean the code wont work or just that u dont have server to test it on?
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  3. #3
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Our List of Jokes</title>
    <meta http-equiv="content-type"
    content="text/html; charset=iso-8859-1" />
    </head>
    <body>
    <?php
    // Connect to the database server
    $dbcnx = @mysql_connect('localhost''root''fun');
    if (!
    $dbcnx) {
    exit(
    '<p>Unable to connect to the ' .
    'database server at this time.</p>');
    }
    // Select the jokes database
    if (!@mysql_select_db('ijdb')) {
    exit(
    '<p>Unable to locate the joke ' .
    'database at this time.</p>');
    }
    ?>
    <p>Here are all the jokes in our database/p>
    <blockquote>
    <?php
    // Request the text of all the jokes
    $result = @mysql_query('SELECT joketext FROM joke');
    if (!
    $result) {
    exit(
    '<p>Error performing query: ' mysql_error() . '</p>');
    }
    // Display the text of each joke in a paragraph
    while ($row mysql_fetch_array($result)) {
    echo 
    '<p>' $row['joketext'] . '</p>';
    }
    ?>
    </blockquote>
    </body>
    </html>
    Put your code in tags to make it easier reading..are you getting any error messages? Have you saved the page as .php as opposed to .html, for example?

  4. #4
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Did you run the code on a server? Did it show any error messages?

  5. #5
    SitePoint Member powerstation79's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webnoob
    Hey, Welcome to the forums When u say "can't" do u mean the code wont work or just that u dont have server to test it on?
    i think i have test it on local server right as you can see on server, right? tell me la, expert, plz

  6. #6
    SitePoint Addict I don`t mind's Avatar
    Join Date
    Feb 2006
    Location
    LA
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $dbcnx = @mysql_connect('localhost', 'root', 'fun');
    if (!@mysql_select_db('ijdb')) {
    exit('<p>Unable to locate the joke ' .
    'database at this time.</p>');
    }
    $result = @mysql_query('SELECT joketext FROM joke');
    if (!$result) {
    exit('<p>Error performing query: ' . mysql_error() . '</p>');
    }
    should be


    $dbcnx = mysql_connect('localhost', 'root', 'fun');
    if (!mysql_select_db('ijdb')) {
    exit('<p>Unable to locate the joke ' .
    'database at this time.</p>');
    }
    $result = mysql_query('SELECT joketext FROM joke');
    if (!$result) {
    exit('<p>Error performing query: ' . mysql_error() . '</p>');
    }
    It won't show any errors .... unable to connect to server etc. .... because of the @ in front of the sql statements so delete them and look what it says
    Words are weapons of Mass Destruction.

  7. #7
    SitePoint Member powerstation79's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face

    thanks

  8. #8
    SitePoint Member powerstation79's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Again fatal

    it browser shows "Fatal error: Call to undefined function mysql_connect() in c:\Inetpub\wwwroot\jokelist.php on line 12"

  9. #9
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've heard thats a result of mysql not being installed...have you had any other problems or is the first mysql type 'project' you've worked on

  10. #10
    SitePoint Member powerstation79's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reply

    Quote Originally Posted by Waffles
    I've heard thats a result of mysql not being installed...have you had any other problems or is the first mysql type 'project' you've worked on
    Yes, this the first mysql type project, can you let me know thw problem?

  11. #11
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Create a file with just the following in it:
    <?php phpinfo() ?>
    Load it up in your browser and you'll see a line telling you where your php.ini file is (something like):
    Configuration File (php.ini) Path C:\WINDOWS\php.ini

    Open the php.ini file and check there's a line:
    extension=php_mysql.dll

    Then restart the web server. See if that helps.

  12. #12
    SitePoint Member powerstation79's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is extenson of the file to be created?

  13. #13
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just call it test.php and put it in c:\Inetpub\wwwroot\ then load up localhost/test.php

  14. #14
    SitePoint Member powerstation79's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reply

    Quote Originally Posted by markl999
    Create a file with just the following in it:
    <?php phpinfo() ?>
    Load it up in your browser and you'll see a line telling you where your php.ini file is (something like):
    Configuration File (php.ini) Path C:\WINDOWS\php.ini

    Open the php.ini file and check there's a line:
    extension=php_mysql.dll

    Then restart the web server. See if that helps.
    I have remove the ; from the extension=php_mysql.dll and then restart the WWP service
    but still no response

  15. #15
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the test.php page do you see a MySQL section with some MySQL related information in it? It might also be worth clearing your browser cache just to make sure

  16. #16
    SitePoint Member powerstation79's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, i didnt found anything related with Mysql section in the test.php? Anyway, can teach how to clear the browser cache?


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
  •