Problem with connecting to MySQL

Discussion in 'PHP' started by nobitavn94, Aug 6, 2006.

  1. #1
    Hi !
    I'm using PHP 5.1.2 and MySQL 5.0 .
    When I use mysql_connect("localhost","root","sa") function (sa is my password to connect to MySQL) and other functions to show a table in a data I created on webpage ,but it display a blank page .I checked very carefully functions i used.I copied even source code from an ebook ,but It also display an blank page.I tested many times
    I'm very disheartened .
    Please help me !.
     
    nobitavn94, Aug 6, 2006 IP
  2. ip076

    ip076 Peon

    Messages:
    79
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you post the source code, it may be easier to help you out.

    You can view this thread for a little function I wrote to do this. You will have to change your values in the mysql_connect and select_db functions.
     
    ip076, Aug 6, 2006 IP
  3. nobitavn94

    nobitavn94 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <HTML>
    <HEAD>
    <TITLE>
    Displaying tables with MySQL
    </TITLE>
    </HEAD>

    <BODY>
    <CENTER>
    <H1>Displaying tables with MySQL</H1>

    <?php
    $connection = mysql_connect("localhost","root","abc")
    or die ("Couldn't connect to server");
    $db = mysql_select_db("produce", $connection)
    or die ("Couldn't select database");

    $query = "SELECT * FROM fruit";
    $result = mysql_query($query)
    or die("Query failed: ".mysql_error());

    echo "<TABLE BORDER='1'>";
    echo "<TR>";
    echo "<TH>Name</TH><TH>Number</TH>";
    echo "</TR>";

    while ($row = mysql_fetch_array($result))
    {
    echo "<TR>";
    echo "<TD>", $row['name'], "</TD><TD>", $row['number'],
    "</TD>";
    echo "</TR>";
    }

    echo "</TABLE>";

    mysql_close($connection);

    ?>
    </CENTER>
    </BODY>
    </HTML>
     
    nobitavn94, Aug 7, 2006 IP
  4. Klian

    Klian Member

    Messages:
    81
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #4
    Its fine for me.

    Have you tested a phpinfo(); document before ?
     
    Klian, Aug 7, 2006 IP
  5. ip076

    ip076 Peon

    Messages:
    79
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yeah, I agree, that code seems to work fine for me. I changed the query to work in my database, but that's it.

    You're not getting MySQL Errors? Just a blank page?
     
    ip076, Aug 7, 2006 IP
  6. sandossu

    sandossu Guest

    Messages:
    2,274
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It looks ok, it should work. anyway, you should get some errors, not a blank page
     
    sandossu, Aug 7, 2006 IP
  7. nobitavn94

    nobitavn94 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    After installing PHP ,I tested with phpinfo(); function.I installed PHP successfully .I uncommented extension :php_mysql.dll,v.v...
     
    nobitavn94, Aug 7, 2006 IP
  8. topwebserv

    topwebserv Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I changed for you please test
     
    topwebserv, Aug 8, 2006 IP
  9. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #9
    What happens if you echo mysql_num_rows($result) before the table?
     
    Gordaen, Aug 8, 2006 IP