SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Zealot pannick's Avatar
    Join Date
    Aug 2003
    Location
    Florida
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to get data form mysql

    I am trying to retrieve data from my MySQL database and get a blank page. Can someone check my code I don't see what is wrong.

    Thanks in advance..

    Here is my code
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Kiwi Syslog Database</title>
    </head>
    <body>
    <?php
    #connect to MySQL
    $conn=@mysql_connect("localhost", "theboss", "theboss")
    or die("Err:Con");
    #select database
    $rs = @mysql_select_db("kiwi_syslog", $conn)
    or die("Err;Db");
    #create the query
    $sql="select * FROM syslog";

    #execute the query
    $rs=mysql_query($sql,$conn);

    #write the data
    while ( $row = mysql_fetch_array($rs) )
    {
    echo("Date: ".$row["MsgDate"]);
    echo("Time: ".$row["MsgTime"]);
    echo("Priority: ".$row["MsgPriority"]);
    echo("Hostname: ".$row["MsgHostname"]);
    echo("Message: ".$row["MsgText"]. "<br>");

    }
    ?>
    </body>
    </html>

  2. #2
    SitePoint Zealot
    Join Date
    May 2005
    Location
    Birmingham UK
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not sure if this will work, im only learning php but try this:

    PHP Code:
     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Kiwi Syslog Database</title>
    </head>
    <body>
    <?php
    #connect to MySQL
    $conn mysql_connect("localhost""theboss""theboss") or die("Connection error:".mysql_error());
    #select database
    $rs mysql_select_db("kiwi_syslog"$conn) or die("Db error:".mysql_error());
    #create the query
    $sql="SELECT * FROM syslog";

    #execute the query
    $rs mysql_query($sql,$conn);

    #write the data
    while ( $row mysql_fetch_array($rs) )
    {
    echo(
    "Date: ".$row['MsgDate']);
    echo(
    "Time: ".$row['MsgTime']);
    echo(
    "Priority: ".$row['MsgPriority']);
    echo(
    "Hostname: ".$row['MsgHostname']);
    echo(
    "Message: ".$row['MsgText']."<br>");

    }
    ?>
    </body>
    </html>
    Last edited by Opserty; Jun 14, 2005 at 13:05. Reason: Correcting php errors
    Contact: opserty@gmail.com
    Register your portfolio at: http://portfoliodb.net

  3. #3
    SitePoint Zealot pannick's Avatar
    Join Date
    Aug 2003
    Location
    Florida
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that is a no go to I get just a blank page

  4. #4
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Kiwi Syslog Database</title>
    </head>
    <body>
    <?php
    #connect to MySQL
    $conn mysql_connect("localhost""theboss""theboss") or die("Connection error:".mysql_error());
    #select database
    $rs mysql_select_db("kiwi_syslog"$conn) or die("Db error:".mysql_error());
    #create the query
    $result mysql_query("SELECT * FROM syslog");


    #write the data
    while ( $row mysql_fetch_assoc($result) )
    {
    echo(
    "Date: ".$row['MsgDate']);
    echo(
    "Time: ".$row['MsgTime']);
    echo(
    "Priority: ".$row['MsgPriority']);
    echo(
    "Hostname: ".$row['MsgHostname']);
    echo(
    "Message: ".$row['MsgText']."<br>");

    }
    ?>
    </body>
    </html>

  5. #5
    SitePoint Zealot pannick's Avatar
    Join Date
    Aug 2003
    Location
    Florida
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fatal error: Call to undefined function mysql_connect() in C:\Inetpub\wwwroot\kiwi\2test.php on line 10

  6. #6
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    looks like you are using PHP5.x, try mysqli_connect() (and the rest of the 'new' mysql functions)
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  7. #7
    SitePoint Zealot pannick's Avatar
    Join Date
    Aug 2003
    Location
    Florida
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The book that I got is PHP5

    I googled it and can't find much am I that much of a putz?

  8. #8
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, what PHP version is installed on your server?
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  9. #9
    SitePoint Zealot pannick's Avatar
    Join Date
    Aug 2003
    Location
    Florida
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The version that I downloaded and installed is php-5.0.4

  10. #10
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please note that PHP5 does not have the MySQL library installed for default.

  11. #11
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, so now change all mysql_... functions into mysqli_...
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  12. #12
    SitePoint Zealot pannick's Avatar
    Join Date
    Aug 2003
    Location
    Florida
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So my php should look like this

    Code:
    <?php
    
    #connect to MySQL
    $conn=@mysqli_connect( "localhost", "mike", "bingo" )
    		 	or die( "Err:Conn" );
    
    #select the specified database
    $rs = @mysqli_select_db( "my_database", $conn ) 
    			or die( "Err:Db" );
    #create the query 
    $sql = "select id, first_name from my_table";
    
    #execute the query
    $rs = mysqli_query( $sql, $conn );
    
    #write the data
    while( $row = mysqli_fetch_array( $rs ) )
    {
       echo("Date: ".$row['MsgDate']); 
    echo("Time: ".$row['MsgTime']); 
    echo("Priority: ".$row['MsgPriority']); 
    echo("Hostname: ".$row['MsgHostname']); 
    echo("Message: ".$row['MsgText']."<br>"); 
    
    }
    
    ?>

  13. #13
    SitePoint Zealot pannick's Avatar
    Join Date
    Aug 2003
    Location
    Florida
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also checked the php.ini to make sure that these are there
    I still just get a blank page
    Code:
     
    extension=php_mysql.dll
    [MySQL]
    ; Allow or prevent persistent links.
    mysql.allow_persistent = On
    
    ; Maximum number of persistent links.  -1 means no limit.
    mysql.max_persistent = -1
    
    ; Maximum number of links (persistent + non-persistent).  -1 means no limit.
    mysql.max_links = -1
    
    ; Default port number for mysql_connect().  If unset, mysql_connect() will use
    ; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
    ; compile-time value defined MYSQL_PORT (in that order).  Win32 will only look
    ; at MYSQL_PORT.
    mysql.default_port =
    
    ; Default socket name for local MySQL connects.  If empty, uses the built-in
    ; MySQL defaults.
    mysql.default_socket =
    
    ; Default host for mysql_connect() (doesn't apply in safe mode).
    mysql.default_host =
    
    ; Default user for mysql_connect() (doesn't apply in safe mode).
    mysql.default_user =
    
    ; Default password for mysql_connect() (doesn't apply in safe mode).
    ; Note that this is generally a *bad* idea to store passwords in this file.
    ; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
    ; and reveal this password!  And of course, any users with read access to this
    ; file will be able to reveal the password as well.
    mysql.default_password =
    
    ; Maximum time (in secondes) for connect timeout. -1 means no limit
    mysql.connect_timeout = 60
    
    ; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
    ; SQL-Errors will be displayed.
    mysql.trace_mode = Off


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
  •