Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

500 - Internal server error on index.php

Discussion in 'General Discussion' started by tekkenfan2, Jun 30, 2014.

  1. tekkenfan2

    tekkenfan2 Registered

    Joined:
    Jun 30, 2014
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Hey guys,
    So I'm making a basic website form to do CRUD operations on a database, and all of my components work, but I keep getting 500 - Internal server error on my index.php
    Heres my code:
    PHP:
    <?php
    require_once('config.php');
    require_once(
    'menu.php');
     
    echo 
    '<h1>View All Alien Interactions</h1>';
     
    /* Start the table with the fields we want to display
    Remember $fields is now in config.php */
    echo '<table>
        <tr>'
    ;
    foreach(
    $fields AS $label){
        
    // th is a table header; the column's title or label.
        
    echo "<th>{$label}</th>";
    }
    //Add the edit and delete columns at the end of the table
    echo '<th>Edit</th><th>Delete</th>';
    echo 
    '</tr>';
    /*
    Select the fields we want, from all the rows
    The first line takes the array keys from our $fields array
    and implodes them, using backticks and commas. The end result
    will look like `first_name`, `last_name`, `phone_number`...
    The next line creates a SELECT query using that string.
    */
     
    $fields_str '`contact_id`, `'.implode(array_keys($fields), '`, `').'`';
    $sql "SELECT {$fields_str} FROM `aliens_abduction`";
     
    foreach(
    $dbh->query($sql) as $row) {
        echo 
    '<tr>';
        
    // Loop through the fields again to display them for this row.
            // Note: The tutorial originally contained an error here, this has been updated.
        
    foreach($fields AS $field=>$value){
            
    // if the field is blank, we want to empty a blank space, otherwise the HTML won't work properly
            
    echo '<td>'.(isset($row[$field]) && strlen($row[$field]) ? $row[$field] : '&nbsp'.'</td>');
        }
        echo 
    '</tr>';
        echo 
    '<td><a href="edit.php?contact_id='.$row['contact_id'].'">Edit</a></td>';
        echo 
    '<td><a href="delete.php?contact_id='.$row['contact_id'].'">Delete</a></td>';
        echo 
    '</tr>';
    echo 
    '</table>';
    ?>
    and heres my config.php code (idk if this is the root of the problem, i dummied out my credentials):

    PHP:
    <?php
    //Connect to the database
    $dbh = new PDO('mysql:host=xxxxxxxxx;dbname=db_demo''xxxxx''xxxxx');
    //Set the default fetch mode to be an associative array.
    $dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,  PDO::FETCH_ASSOC);
     
    //Define the fields for our CRUD application
    $fields = array(
        
    'first_name' => 'First Name',
        
    'last_name' => 'Last Name',
        
    'when_it_happened' => 'When it happened',
        
    'how_many' => 'How many',
        
    'alien_description' => 'Alien description',
        
    'what_they_did' => 'What they did',
        
    'fang_spotted' => 'Fang spotted',
        
    'email' => 'Email'
    );
    ?>
     
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,233
    Likes Received:
    1,939
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello :)

    Please post the output from /usr/local/apache/logs/error_log when the "500" error code appears.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice