SitePoint Sponsor

User Tag List

Results 1 to 24 of 24
  1. #1
    SitePoint Member
    Join Date
    May 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Php & Mysql Problem

    i am reading the book

    "BUILDING YOUR OWN DATABASE DRIVEN WEBSITE USING PHP & MYSQL" and im stuck. i tried the example with the joke database but it doesnt seem to work. ive successfull created the table but when i write the code to display the data nothing comes up.

    here is my code

    PHP Code:
    <html>
    <head>
    <title>our list of jokes</title>
    <head>
    <body>

    <?php


    $dbcnx 
    = @mysql_connect('localhost''root''mypasswd');
    if (!
    $dbcnx) {
        exit(
    '<p>Unable to connect to the ' .
        
    'database server at this time.</p>');
    }

    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

    $result 
    = @mysql_query('SELECT joketext FROM joke');
    if (!
    $result) {
        exit(
    '<p>Error performing query: ' .mysql_error() . '</p>');
    }




    while (
    $row mysql_fetch_array($result)) {
        echo 
    '<p>' $row['joketext'] . '</p>';
    }

    ?>

    </blockquote>
    </body>
    </html>

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Do you have anything entered in a db table?

    You might want to add a check to see if query returned any results?

    PHP Code:
    <html>
    <head>
    <title>our list of jokes</title>
    <head>
    <body>

    <?php


    $dbcnx 
    = @mysql_connect('localhost''root''mypasswd');
    if (!
    $dbcnx) {
        exit(
    '<p>Unable to connect to the ' .
        
    'database server at this time.</p>');
    }

    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

    $result 
    = @mysql_query('SELECT joketext FROM joke');
    if (!
    $result) {
        exit(
    '<p>Error performing query: ' .mysql_error() . '</p>');
    }

    if(
    mysql_num_rows($result) == 0)
    {
        echo 
    '<p>No jokes at the moment.</p>';
    }


    while (
    $row mysql_fetch_array($result)) {
        echo 
    '<p>' $row['joketext'] . '</p>';
    }

    ?>

    </blockquote>
    </body>
    </html>
    -- Jelena --

  3. #3
    SitePoint Member
    Join Date
    May 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i just tried this code. the same thing. just a blank screen comes up. i have saved the file as jokelist.php in my C:\Inetpub\wwwroot folder.

    i type localhost/jokelist.php and nuthing comes

    yes there is in my table. i have added one line only. one joke and one date.

  4. #4
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using http://localhost/jokelist.php, your basic non php html code and echo statements should show if the php file is being processed.

    Byron Thomas

  5. #5
    SitePoint Member
    Join Date
    May 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nothing same again. blank page

  6. #6
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Michigan
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you view the source of the blank page is there any HTML tags or nothing at all?

  7. #7
    SitePoint Member
    Join Date
    May 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there is only up to the body part


    <html>
    <head>
    <title>our list of jokes</title>
    <head>
    <body>

  8. #8
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take the following and place it into a file called info.php :

    PHP Code:
    <?php
    phpinfo
    ();
    ?>
    Load this page into a web browser, You have not said but I take it that you are using IIS on the same computer you are browsing on. If you are on a workstation and your server is a different machine you will need to use the IP address of the server, I work on a network and my serverhas an IP address of 192.168.0.1.
    Otherwise http://localhost/info.php should output the php configuration information of your installed version of php. If you get a blank page you need to reconfigure your installation.

    Byron Thomas

  9. #9
    SitePoint Member
    Join Date
    May 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php info works ok

    what can i do now

  10. #10
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take the @ error suppressions out of your code.

    Byron Thomas

  11. #11
    SitePoint Member
    Join Date
    May 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is what i got now

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\Inetpub\wwwroot\jokelist.php on line 11

    We were unable to connect to the database server at this time.

  12. #12
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use the following code :

    PHP Code:
    function db_open(){
        
    $db mysql_connect('localhost''app_User_Name''password');
        if (!
    $db) {
            die(
    'Could not connect: ' mysql_error());
        }
        
        
    mysql_select_db'Database_to_use' );
        
        if (
    mysql_errno()) {
            echo 
    'Could not open connection<br>';
            echo 
    'Error Number : ' .mysql_errno();
            exit;
            } Else {
                return 
    $db;
            }

    Make sure you create a user name for your app and that user has select privileges and any other needed within this app, such as insert , update or delete.

    Byron Thomas

  13. #13
    SitePoint Member
    Join Date
    May 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i took this code from the book. thats why i used it. im not very familiar with php yet.

  14. #14
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use whichever code you are comfortable with, to solve the problem go to your mysqladmin and create a user besides 'root'.

    mysql> grant select, insert, update, delete
    on ijdb
    to [User Name] identified by 'mypasswd';

    Byron Thomas

  15. #15
    SitePoint Member
    Join Date
    May 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i downloaded mysql admin. now i gotta create a username? and put it in my code?

    what does the above code mean u wrote

    mysql> grant select, insert, update, delete
    on ijdb
    to [User Name] identified by 'mypasswd';

    i just tried to connect to mysql admin but cannot. it is asking me for password

  16. #16
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That would be the command you could run from a command-line interface after logging into mysql. How did you create the table? Did you log in to mysql via a command-line prompt? mysql -h hostname -u username -p? How did you set a password for the root user?

    Byron Thomas

  17. #17
    SitePoint Member
    Join Date
    May 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i didnt set a password for root as said in the book
    yes through command line.

  18. #18
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you install mysqladmin?
    Under user administration you should be able to create a user and assign a password to that user for the ijdb.

  19. #19
    SitePoint Member
    Join Date
    May 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i did but when i start it this comes up and i dont know what to do

    http://img526.imageshack.us/img526/7623/adminwn5.jpg

  20. #20
    SitePoint Member
    Join Date
    May 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i created a new username and inserted it into my php code. but the problem still remains

  21. #21
    SitePoint Member
    Join Date
    May 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i need help guys!!!!

  22. #22
    SitePoint Evangelist superuser2's Avatar
    Join Date
    Aug 2006
    Posts
    598
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm... the database is running at localhost on port 3306 (default MYSQL port)?

    Make sure "localhost" is allowed to connect as well.

  23. #23
    SitePoint Member
    Join Date
    May 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i ve done the database on my webhost now and still not working. i dont know whats wrong

    Warning: mysql_query() [function.mysql-query]: Access denied for user 'georgeuk'@'localhost' (using password: NO) in /home/georgeuk/public_html/jokelist.php on line 46

    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/georgeuk/public_html/jokelist.php on line 46

    Error performing query: Access denied for user 'georgeuk'@'localhost' (using password: NO)

  24. #24
    SitePoint Evangelist superuser2's Avatar
    Join Date
    Aug 2006
    Posts
    598
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're not sending them our password. Please show us your current connection code (replace your password with "*"s but don't change your original code.


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
  •