Jump to content

VexedDeveloper

New Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by VexedDeveloper

  1. Hi all,

    I am trying to use POST variables in my SQL query string:

     

    I am running the PHP script on IIS and I am getting these errors:

    var dumb of the $getresults:

    bool(false)
    Notice: Array to string conversion in C:\inetpub\wwwroot\phpinfo.php on line 27
    Array
    Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in C:\inetpub\wwwroot\phpinfo.php on line 28

    Warning: sqlsrv_free_stmt() expects parameter 1 to be resource, boolean given in C:\inetpub\wwwroot\phpinfo.php on line 35

    What am I doing wrong?

     

    Thanks in advance.
     

    <?php
    
        $serverName = "something.database.windows.net";
        $connectionOptions = array(
            "Database" => "something",
            "Uid" => "something",
            "PWD" => "something"
        );
        //Establishes the connection
        $conn = sqlsrv_connect($serverName, $connectionOptions);
    
        $tableName = 0;
        $columnName = 0;
        $tsql = null;
        if(isset($_POST['dbName'])) {
    
            $tableName = $_POST['dbName'];
            $columnName = $_POST['columnName'];
    
        }
        $tsql = "SELECT $columnName FROM $tableName";
        //"SELECT ProductName, ProductId FROM ProductData";// . $columnName .  "FROM "  . $tableName;
        $getResults= sqlsrv_query($conn, $tsql);
        var_dump($getResults);
        if ($getResults == FALSE)
            echo (sqlsrv_errors());
        while ($row = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC)) {
            echo($row['ProductName'] . "\r\n" . PHP_EOL);
            //echo($row['ProductId'] . "<br>" . PHP_EOL);
            //$row = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC);
            //echo ($row['ProductName'] . "\n" . PHP_EOL);
        }
    
        sqlsrv_free_stmt($getResults);
    
        ?>

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.