SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    UK
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post pulling data from mysql db

    i am trying to pull site content from a database using php and mysql. below is the code i am using and underneath the error it is generating

    <html>

    <head>

    <title>MySQL Connect</title>

    </head>

    <body>

    <?php

    // connect to database server
    $dbconn = @mysql_connect("[dbserver]","[user]","[password]");

    // select database
    $dbselect = @mysql_select_db("Content", $dbconn);

    // select content entry from database
    $result = @mysql_query("SELECT PageContent FROM content");

    // display content
    while ( $row = mysql_fetch_array($result) ) { // ** this is row 23 **
    echo ("<p>" . $row["PageContent"] . "</p>");
    }

    ?>

    </body>

    </html>

    the error message is as follows...

    Warning: Supplied argument is not a valid MySQL result resource in /web/sites/31/azaar/www.azaar.f2s.com/php/mysql/index.php on line 23

    i would appreciate it if anyone could determine what i am doing wrong.

    nb. there IS data in column 'PageContent' in the 'content' db.

    thanks for your time

    Azaar

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2001
    Location
    Earth
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It appears that there is something wrong with your SQL statement "SELECT PageContent FROM content".

    Can you just try running that statement from phpmyadmin or a mysql client? Are you sure you don't have any typo's in the column name or table name?

    Frank
    http://www.serverexpert.com/ Discuss servers and the software that makes them work.
    http://www.webmasters-resources.com/ Resources for webmasters.

  3. #3
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    UK
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i had tried it in phpMyAdmin and it successfully returned the entries.

    table is 'content'
    column is 'PageContent'

  4. #4
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where you have actually declared the table that you are working on (on line 17 I think) you have named your table as Content but when running your query you have called it content. I am very new to PHP (I am currently in the middle of writing my first website myself) so that may not be the cause but I know linux boxes are really picky on case sensitivity so it wont find the table you are trying to pull information from

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Error Checking Error Checking! Right now you are supressing all your errors, you are nerver gonna find out whats wrong like that. Try this:


    PHP Code:
    // connect to database server 
    $dbconn mysql_connect("[dbserver]","[user]","[password]") OR DIE(mysql_error()); 

    // select database 
    $dbselect mysql_select_db("Content"$dbconn) OR DIE(mysql_error()); 

    // select content entry from database 
    $result mysql_query("SELECT PageContent FROM content") OR DIE(mysql_error()); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    UK
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    solution

    ok - thnx 2 all of u for your help, i have now solved it.

    lee34's point about the capitalisation made me realise that i was using the table name in the place of the db name (doh!)

    the page now works, so thanks to all - and thnx for the advice freddy.

    Azaar


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
  •