0

Newbie question: I am connecting php to SQL Server for the first time. The connection has been established, using the sqlsrv_connect function.

I am now trying to return rows, but it returns this error:

Undefined index: Version in [FilePath] on line 62

<?php

    $sql = "SELECT @@VERSION AS [version]";

    $stmt = sqlsrv_query( $conn, $sql);

    if($stmt === false) //if the query returns no rows
    {
      die(print_r(sqlsrv_errors(), true));
    };

    //echo the opening definition of the table in HTML5

    echo "<table>
            <tr>
                <th>Version</th>
            </tr>";

            //echo the rows returned
            while( $row = sqlsrv_fetch_Array($stmt, SQLSRV_FETCH_ASSOC) ) 
            {
                echo "<tr>";
                echo "<td>".$row['Version']."</td>" ; //<<- This is line 62
                echo "</tr>";
            }

    //close the table tag
    echo "</table>";

?>

I expect this is such a newb question, and I am missing something really obvious. I'm not a PHP coder, as you can probably imagine.

Update: Appreciated that this question is related to the answer in another question, but really, my question is definitely different, because the solution was different. The solution here has to do with the case of the characters in the code.

user3469285
  • 181
  • 1
  • 1
  • 9
  • 4
    `$row['Version']` should be `$row['version']` – Nick Apr 10 '19 at 23:17
  • 1
    Possible duplicate of ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) –  Apr 10 '19 at 23:24

1 Answers1

0

Seriously! Ok, thanks to Nick, who rightly identified in the comments that my column name needed to be lowercase. Blast my newbieness!

$row['Version']

should be

$row['version']

user3469285
  • 181
  • 1
  • 1
  • 9