1

I'm developing a code to insert data and print a list of products from a database in MS SQL and using a IIS server (for first time). Is imposible display errors (even setting on php.ini) and I haven't used PHP for a year, so I don't know what is wrong in my code. I'm not the administrator and he is busy, so it's difficult see the log file too. The web service only show "500 - Internal server error". Please help me to find a solution. There is the code:

<?php

$serverName = "server\SQLEXPRESS";
$connectionInfo = array( "Database"=>"dbName", "UID"=>"userID", "PWD"=>"pass");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$sql = "SELECT * FROM products";

if( $conn ) {
     $stmt = sqlsrv_query( $conn, $sql);
     print_r($stmt);
     if( $stmt === false ) {
         die( print_r( sqlsrv_errors(), true));
}
}else{
     echo "Conexión no se pudo establecer.<br />";
     die( print_r( sqlsrv_errors(), true));
}

echo '<!DOCTYPE html>';
echo '<html>';
echo '<head>';

echo '<meta charset="utf-8">';
echo '<meta http-equiv="X-UA-Compatible" content="IE=edge">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1">';
echo '<meta name="description" content="">';
echo '<meta name="author" content="">';

echo '<title>Products</title>';

echo '<link href="/startbootstrap-sb-admin-2-gh-pages/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">';
echo '<link href="/startbootstrap-sb-admin-2-gh-pages/vendor/metisMenu/metisMenu.min.css" rel="stylesheet">';
echo '<link href="/startbootstrap-sb-admin-2-gh-pages/dist/css/sb-admin-2.css" rel="stylesheet">';
echo '<link href="/startbootstrap-sb-admin-2-gh-pages/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">';

echo '</head>';
echo '<body>';
    echo '<div class="container">';
        echo '<br>';
            echo '<div class="row">';
                echo '<div class="col-lg-12">';
                    echo '<a href="/Access.html"><button type="button" class="btn btn-default">Back</button></a>';
                echo '</div>';
            echo '</div>';
        echo '<br>';
            echo '<div class="row">';
                echo '<div class="col-lg-12">';
                    echo '<div class="panel panel-primary">';
                        echo '<div class="panel-heading">';
                            echo '<h3 class="panel-title">Add product</h3>';
                        echo '</div>';
                        echo '<div class="panel-body">';
                            echo '<form role="form" action="\addActProduct.php" method="post">';
                                echo '<fieldset>';
                                    echo '<div class="form-group">';
                                        echo '<input type="text" class="form-control" name="a" placeholder="a" autofocus>';
                                        echo '<input class="form-control" type="text" name="b" placeholder="b">';
                                        echo '<input class="form-control" type="text" name="c" placeholder="c">';
                                        echo '<input class="form-control" type="text" name="d" placeholder="d">';
                                    echo '</div>';
                                    echo '<div class="form-group">';
                                        echo '<input class="form-control" type="text" name="e" placeholder="e">';
                                        echo '<input class="form-control" type="text" name="f" placeholder="f">';
                                        echo '<input class="form-control" type="text" name="g" placeholder="g">';
                                        echo '<input class="form-control" type="text" name="h" placeholder="h">';
                                    echo '</div>';
                                    echo '<input class="btn btn-lg btn-primary btn-block" type="submit" value="Introducir">';
                                echo '</fieldset>';
                            echo '</form>';
                        echo '</div>';
                    echo '</div>';
                echo '</div>';
            echo '</div>';
        echo '<div class="row">';
            echo '<div class="col-lg-12">';
                    echo '<div class="panel panel-default">';
                        echo '<div class="panel-heading">';
                            echo 'Listado de productos';
                        echo '</div>';
                       echo ' <!-- /.panel-heading -->';
                        echo '<div class="panel-body">';
                            echo '<div class="table-responsive">';
                               echo ' <table class="table">';
                                    echo '<thead>';
                                       echo ' <tr>';
                                            echo '<th>a</th>';
                                            echo '<th>b</th> ';
                                            echo '<th>c</th>';
                                            echo '<th>d</th>';
                                            echo '<th>e</th>';
                                            echo '<th>f</th> ';
                                            echo '<th>g</th>';
                                            echo '<th>h</th>';
                                            echo '<th>i</th>';
                                        echo '</tr>';
                                    echo '</thead>';
                                    echo '<tbody>';
                                        if (count($stmt) > 0) {
                                            foreach ($stmt As $stmts){
                                                echo '<tr class="info">';
                                                echo '<td>'.$stmts['a'].'</td>';
                                                echo '<td>'.$stmts['b'].'</td>';
                                                echo '<td>'.$stmts['c'].'</td>';
                                                echo '<td>'.$stmts['d'].'</td>';
                                                echo '<td>'.$stmts['e'].'</td>';
                                                echo '<td>'.$stmts['f'].'</td>';
                                                echo '<td>'.$stmts['g'].'</td>';
                                                echo '<td>'.$stmts['h'].'</td>';
                                                echo '<td><a href="/modProduct.php/?idProd='.$stmts['i'].'"><button type="button" class="btn btn-default" name="Mod">Mod</button></a>';
                                                echo '<a href="/delActProduct.php/?idProd='.$stmts['i'].'"><button type="button" class="btn btn-danger" name="Del">Del</button></a></td>';
                                                echo '</tr>';
                                            }
                                        }                                   
                                    echo '</tbody>';
                                echo '</table>';
                            echo '</div>';
                           echo ' <!-- /.table-responsive -->';
                        echo '</div>';
                        echo '<!-- /.panel-body -->';
                    echo '</div>';
                    echo '<!-- /.panel -->';
            echo '</div>';
                echo '<!-- /.col-lg-6 -->';
        echo '</div>';
    echo '</div>';

echo '<script src="/startbootstrap-sb-admin-2-gh-pages/vendor/jquery/jquery.min.js"></script>';
echo '<script src="/startbootstrap-sb-admin-2-gh-pages/vendor/bootstrap/js/bootstrap.min.js"></script>';
echo '<script src="/startbootstrap-sb-admin-2-gh-pages/vendor/metisMenu/metisMenu.min.js"></script>';
echo '<script src="/startbootstrap-sb-admin-2-gh-pages/dist/js/sb-admin-2.js"></script>';

echo '</body>';
echo '</html>';
Tilan04
  • 86
  • 1
  • 7
  • for error message you have to look to log file – Kazz Jun 20 '17 at 08:37
  • https://stackoverflow.com/questions/6426375/where-can-i-find-the-iis-logs – Kazz Jun 20 '17 at 08:38
  • I go to edit my post to add that I'm not the administrator and he is busy, so it's difficult see the log file too. – Tilan04 Jun 20 '17 at 08:42
  • Just want to say that it is possible to display errors on screen with iis+php a quick google search will do it https://www.google.co.uk/search?q=display+php+errors+iis&rlz=1C5CHFA_enGB745GB745&oq=display+php+errors+iis&aqs=chrome..69i57j0l4.11706j0j7&sourceid=chrome&ie=UTF-8#q=how+to+display+php+errors+iis – Claudio Pinto Jun 20 '17 at 08:43
  • yes but not 500 internal error – Kazz Jun 20 '17 at 08:47

1 Answers1

0

How are you accessing the website ,are you accessing using any other url than localhost? IIS does not display detailed errors if the url is anything other than localhost. You have to make sure two things

  1. have logging set to error_reporting = E_ALL, and display_errors = On in your php.ini
  2. if you want to show detailed errors ,you have to disable customerrors setting in IIS web.config file. Or in the IIS manager ,go to the configuration editor this is under system.webServer->httpErrors. You will need to change errorMode to Detailed from DetailedLocalOnly .

All these require access to Administrator if you do not have access to the server.

 <!-- Web.Config Configuration File -->

    <configuration>
        <system.web>
            <customErrors mode="Off"/>
        </system.web>
    </configuration>
Rohith
  • 5,527
  • 3
  • 27
  • 31