Results 1 to 10 of 10

Thread: Problem reading mysql table with php

  1. #1
    Join Date
    Apr 2011
    Beans
    12

    Problem reading mysql table with php

    Hi all,

    I have installed mysql, apache2 and php5. they work fine. But when I try to read a table with php it shows me the blank page. Have i left any thing? I need to know. Here's the code I've used.

    PHP Code:
    <?
    $c = mysql_connect("localhost","vinay","vinay");
    mysql_select_db("myweb",$c);

    $res = mysql_query("select * from member_info",$c);
    $data = mysql_fetch_array($res);
    print "<pre>";
    print_r ($data);
    print "</pre>";
    ?>
    Please reply me asap.

    Thank you.
    Last edited by vinaykumarjg; June 18th, 2011 at 08:13 AM.

  2. #2
    Join Date
    Jan 2010
    Location
    England
    Beans
    78
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Problem reading mysql table with php

    I'd guess you're getting a blank page because error reporting is off. is it not mysql_fetch_assoc or mysql_fetch_array?

    put the following after the <?php tag
    Code:
    error_reporting(E_ALL);
    don't forget to remove it in production
    Shiny Lenovo B560, bought with 50% discount from the Linux Foundation, Ubuntu 11.04 Natty

    If it can go wrong, it will... Multiple times.

  3. #3
    Join Date
    Nov 2010
    Beans
    125
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Problem reading mysql table with php

    try this:


    Code:
    	$conn = new mysqli('domain', $user, $pwd, 'database') or die ('Cannot open database');
    	
    	
    	
    	$sql = "SELECT * FROM table";
    	$result = $conn->query($sql) or die(mysqli_error());
            while ($row = $result->fetch_assoc()){
                     // do something with the current record
             }
    I like unity, gnome and xfce

  4. #4
    Join Date
    Apr 2011
    Beans
    12

    Re: Problem reading mysql table with php

    Thanks for the reply. But both of the ways still leaves me blank page. Is there any wrong with the configuration?

  5. #5
    Join Date
    Nov 2010
    Beans
    125
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Problem reading mysql table with php

    follow this:

    HTML Code:
    http://www.willfitch.com/mysqli-tutorial.html
    first case you must call the variables according to your sql string.

    Second case the problem could be with your domain string, put an echo after the die. That way you can see if the code is going after die.
    I like unity, gnome and xfce

  6. #6
    Join Date
    Jul 2006
    Location
    Calgary, Alberta
    Beans
    1,123
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: Problem reading mysql table with php

    Code:
    $sql = mysql_query("select * from member_info");
    $sqlRow = mysql_fetch_assoc($sql);
    echo "value: " . $sqlRow['column'];
    Replace column with the name of the column you want to get the value from.

    If that doesn't work, you did something wrong.
    Quote Originally Posted by Tristam Green View Post
    I can tell you something about a turntable.
    I have two of them.
    And a microphone.
    Where it's at.

  7. #7
    Join Date
    Apr 2011
    Beans
    12

    Re: Problem reading mysql table with php

    thanks a lot. It solved my problem. But I have a question. I need to why did the previous code didn't work?
    Is there any other ways to solve the problem.


    Thanks again.



    vinay

  8. #8
    Join Date
    Apr 2011
    Beans
    12

    Re: Problem reading mysql table with php

    Quote Originally Posted by dozycat View Post
    follow this:

    HTML Code:
    http://www.willfitch.com/mysqli-tutorial.html
    first case you must call the variables according to your sql string.

    Second case the problem could be with your domain string, put an echo after the die. That way you can see if the code is going after die.

    PHP Code:
    Thats a great tutorialThanks dozycat

  9. #9
    Join Date
    Nov 2010
    Beans
    125
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Problem reading mysql table with php

    maybe mysql_fetch_assoc instead of mysql_fetch_a?
    I like unity, gnome and xfce

  10. #10
    Join Date
    Jul 2006
    Location
    Calgary, Alberta
    Beans
    1,123
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: Problem reading mysql table with php

    Quote Originally Posted by dozycat View Post
    maybe mysql_fetch_assoc instead of mysql_fetch_a?
    Yes, you were missing 4 letters from this line.
    Quote Originally Posted by Tristam Green View Post
    I can tell you something about a turntable.
    I have two of them.
    And a microphone.
    Where it's at.

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
  •