2

Below are my code :

  $conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {

}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}


$sql = 'SELECT [group_id],[type] FROM Users';
$stmt = sqlsrv_query($conn,$sql);

if($stmt == false)
{
    if( ($errors = sqlsrv_errors() ) != null) {
        foreach( $errors as $error ) {
            echo "SQLSTATE: ".$error[ 'SQLSTATE']."<br />";
            echo "code: ".$error[ 'code']."<br />";
            echo "message: ".$error[ 'message']."<br />";
        }
}
}

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

    while ($row=sqlsrv_fetch_Array($stmt,SQLSRV_FETCH_ASSOC))
    {
        echo "<tr>";
        //echo "<td>".$row['users_id']."</td>";
        echo "<td>".$row['group_id']."</td>";
        echo "<td>".$row['type']."</td>";
        //echo "<td>".$row['fname']."</td>";
        //echo "<td>".$row['reg_date']."</td>";
        //echo "<td>".$row['contact']."</td>";
        //echo "<td>".$row['line1'].$row['line2']."</td>";

        echo "</tr>";


    }
echo"</table>";

Below is my error:

  1. SQLSTATE: 42S22
  2. code: 207
  3. message: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name 'group_id'.

SQLSTATE: 42S22 code: 207 message: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name 'type'.

below are link to screenshot of my database; enter image description here enter image description here

As you can see.It says that invalid column.But i pretty sure the column name is same as in my sql server.i do not know what is wrong,can somebody help me.

7
  • You need to provide an example of the database table so we can actually check this
    – Onfire
    Apr 13, 2018 at 3:58
  • i already edit my question,thanks Apr 13, 2018 at 4:20
  • Are you sure the table is 'Users'
    – Onfire
    Apr 13, 2018 at 4:24
  • You should var_dump($row) inside the loop so you know what is available
    – Onfire
    Apr 13, 2018 at 4:26
  • @Onfire yes,table name is users,column name other than group_id and type can be fetch and displayed,the error is only on group_id ,type and reg_date Apr 13, 2018 at 6:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.