What's wrong with this php code?

Discussion in 'Programming' started by aakk, Apr 20, 2008.

  1. #1
    I am trying to do a very simple thing of listing records in MySQL database.

    I have db called 'property' with a table property_list
    I can access the database using MySQL Query browser with no problems and also execute there the same query which gives me desired results.

    I am using in this php the same username and password to connect to db so I imagine I am connecting to db ok especially as I do not get any errors.

    However, when I execute the code below in the browser, all that I get as a result in a browser window is the following:

    "; } mysql_close($con); ?>

    which represent few last line(s) of php

    What am I doing wrong?


    Many thanks!


    ================================================
    <?php
    $con = mysql_connect("localhost","root","cvfs");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("property", $con);

    $result = mysql_query("SELECT * FROM property_list");

    while($row = mysql_fetch_array($result))
    {
    echo $row['property_ref'] . " " . $row['property_short_title'];
    echo "<br />";
    }

    mysql_close($con);
    ?>
    ================================================
     
    aakk, Apr 20, 2008 IP
  2. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you view the source code of the page, you'll probably see the whole code there. It looks like you don't have PHP set up correctly on your server.
     
    TwistMyArm, Apr 20, 2008 IP
  3. aakk

    aakk Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks on your reply. I have only installed MySQL and thought this is enough, obviously not!

    I looked on the web on installing php environment, do I have to install Apache server too or installing php will be enough?

    Thanks.
     
    aakk, Apr 20, 2008 IP
  4. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    just find a bundled apache + php + mysql server. it's easier to develop at your home.
    Try to install xampp or wamp.
     
    fairuz.ismail, Apr 20, 2008 IP
  5. CPURules

    CPURules Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yeah, install XAMPP [apachefriends.org]

    It's pretty straightforward. Once it's installed(I installed to C:\XAMPP) put all of your files in the HTDOCS folder, which for me is C:\XAMPP\htdocs
     
    CPURules, Apr 20, 2008 IP