Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    16
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Failed to retrieve certain column data from database

    Hi
    Thanks a lot for the guidlines, is very helpful and I realise my mistakes too. Now i have another problem is that I can't retrieve certain column (full_name and ic_number)from the database into a table form. I wondering what is my problem here.

    PHP Code:
    <?php        
            
    //Connect to the MySQL server
            
    $db_host "localhost";
            
    $db_username "root";
            
    $db_password "fsktm";
            
    $server mysql_connect($db_host,$db_username,$db_password)or die("Could not connect!/n");
            
            
    //Select a database that has created
            
    $db_name "cinema";
            
    mysql_select_db($db_name)or die("Could not select the database $db_name!\n");
        
        
            
    //Retrieve or select the data
            
    $retrieve mysql_query("SELECT *FROM user") or die(mysql_error());
        
                echo
    "<table border = 1 width = 100% height = 100% style = 'background-color:#F0F8FF;'>
                <tr>
                <th>Username</th>
                <th>Password</th>
                <th>Full Name</th>
                <th>IC Number</th>
                <th>Telephone</th>
                <th>Email</th>
                <th>History</th>
                </tr>"
    ;
            
                
    //Display the data from the database in a table using aray
                
    while($row mysql_fetch_array($retrieve))
                {
                    echo 
    "<tr>";
                    echo
    "</td><td>";
                    echo 
    $row['username'];
                    echo 
    "</td><td>";
                    echo 
    $row['password'];
                    echo 
    "</td><td>";
                    echo 
    $row['fullname'];
                    echo 
    "</td><td>";  
                    echo 
    $row['ic'];
                    echo 
    "</td><td>";  
                    echo 
    $row['telephone'];
                    echo 
    "</td><td>";  
                    echo 
    $row['email'];
                    echo 
    "</td><td>";  
                    echo 
    $row['history'];
                    echo 
    "</tr>";
                }
          
                echo 
    "</table>";

                
    mysql_close($server);
        
    ?>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,855
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Put
    PHP Code:
    ini_set('display_errors',1);
    ini_set('display_startup_errors',1);
    error_reporting (E_ALL); 
    at the top of your code, to reveal all errors (including the one in your query).
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    pelehelp (03-28-2009)

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    16
    Thanks
    9
    Thanked 0 Times in 0 Posts
    After I include the codes that u have suggested, the error mas shows that "Undefined index: fullname and ic", but I ady checked the database, both of the fullname and ic do show in the database; it only failed to be shown in the table created.So, I'm still wonder what was the problem occured?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,855
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Didn't you get a mysql error message?
    $retrieve = mysql_query("SELECT *FROM user") or die(mysql_error());
    should be
    Code:
    $retrieve = mysql_query("SELECT * FROM user") or die(mysql_error());
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    pelehelp (03-28-2009)

  • #5
    New Coder
    Join Date
    Mar 2009
    Posts
    16
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Yup, it displayed an error msg 'Undefined index:fullname and ic'.Therefore, the data from these two columns couldn't be displayed in table. But when I cheched thro the database, the data can be shown.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •