SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Beginner - Simple Question - Maybe?

    I am fairly new to programming using PHP and MySQL. I have been reading Kevin Yank's book titled, "Building a Database-Driven Web Site Using PHP and MySQL". I'm at the very beginning where I'm trying to make an initial connection to my test database in order to display the four records via Internet Explore. The problem is.......I can't get it to work and I've been trying different processes of elimination for over 3 hours - Ouch! I've attached my simple code below. My MySQL server (localhost), database (event) and one table (volunteers) are working just fine, as I'm able to do everything from the command line that I want.

    I've think I've pinpointed the problem to the initial MySQL connection string. It doesn't seem to be making the initial connection to the MySQL server which is on the same workstation I'm programming on, however I have no proof of this. I've tried to find out the value of $dbcnx using echo, but no luck.

    I feel like I'm missing something really basic. The only thing that appears when I run the page below are the two lines at the top. Other sample PHP code runs just fine on my workstation, as long as it isn't connecting to a MySQL database on localhost. BTW, I haven't seen any of the error trapping messages in the code below, even though my understanding is that I should if there's problem connecting to MySQL, the database, etc?

    Any ideas? I've done a considerable amount of programming in the past using Fortran, VBScript, C+, etc., so I'm not new to programming. The fact is I've run into many, many scenarios where the problem turns out to be "that one little thing" I overlooked. The book discusses version 4.x of PHP and I downloaded and installed version 5.2.3, if that makes any difference. I do notice that if I purposely put a syntax error into my PHP code, a blank page appears instead of a page with the top 2 lines. This has helped me rule out a syntax issue, I think.

    I've been told PHP and MySQL are so easy, so this is making me very frustrated as you can imagine. Any assistance would be greatly appreciated!

    (P.S. Yes, "password" is my root password, in case you are wondering after seeing the code below.)

    --Chris
    chrisrima@gmail.com

    *****************
    <HTML><HEAD><TITLE> Event 2007 - Volunteer Registration </TITLE></HEAD><BODY>

    <P><H1>Event 2007</H1><P>
    <P><H2>Volunteer Check-In</H2><P>

    <?php

    $dbcnx = mysql_connect("localhost", "root", "password");

    if (! $dbcnx) {
    echo( "<P>Unable to connect to the database server at this time.</P>" );
    exit();
    }

    if (! @mysql_select_db("event") ) {
    echo( "<P>Unable to locate the volunteers database at this time.</P>" );
    exit();
    }

    mysql_select_db("event", $dbcnx);

    $sql1 = "SELECT * FROM volunteers";

    $result = mysql_query($sql1);

    if (! $result) {
    echo("<P>Error performing query: " . mysql_error() . "</P>");
    exit();
    }

    while ( $row = mysql_fetch_array($result) ) {
    echo("<P>" . $row["FirstName"] . "</P>");
    }

    ?>

    </BODY></HTML>
    ********************

  2. #2
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:

    PHP Code:
    error_reporting(E_ALL);

    mysql_connect("localhost""root""password") or die(mysql_error());

    mysql_select_db("event") or die(mysql_error());

    $sql1 "SELECT * FROM volunteers";

    $result mysql_query($sql1) or die(mysql_error());

    while ( 
    $row mysql_fetch_array($result) ) {
    echo(
    "<P>" $row["FirstName"] . "</P>");

    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.

  3. #3
    SitePoint Enthusiast wyte raven's Avatar
    Join Date
    Feb 2007
    Location
    England, High Wycombe Bucks
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hiya mate!

    Yes can you just read this post and see if this relates to you:

    http://www.sitepoint.com/forums/show...35#post3320835

    I followed the same book and determined that something was wrong "other" than a syntax error. It didn't take me long to realise I had infact had different directory settings, which meant PHP and Mysql didn't communicate with each other correctly. I'm suspecting that because you are using verion 5 you are indeed having the same problem as I have had. Especially if you haven't passed chapter four yet.

    Let me know.
    Wyte R@ven - Creator of the Rift

  4. #4
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thank you

    Thank you for the response. It was very helpful! PHP installed by default to c:\program files\php. I didn't have an /ext directory now any extensions installed in the /ext directory, so I downloaded all of them from php.net and set the extension_dir variable in the php.ini file to ./ext/ and everything works beautifully now. I really appreciate the quick response and helping us new guys when you don't have to! I'm really getting into this PHP stuff! :P

    --Chris

  5. #5
    SitePoint Enthusiast wyte raven's Avatar
    Join Date
    Feb 2007
    Location
    England, High Wycombe Bucks
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Your welcome

    Thats what we are all here for.........to make each others lives much easier in the PHP world.
    Wyte R@ven - Creator of the Rift


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
  •