Muncul Pesan Warning: odbc_exec(): supplied resource is not a valid saat Insert Data ke SQL Server

Saya sudah berhasil mengkoneksikan ke SQL Server,namun saat saya INSERT data muncul pesan Warning: odbc_exec(): supplied resource is not a valid ODBC-Link resource in C:\xampp\htdocs\phpCon\index.php on line 17.
Saya menggunakan XAMPP php versi 7.3.2 dan SQL Server 2012
Mohon bantuannya kak.

$serverName = "DESKTOP-2P6S23P"; //serverName\instanceName

// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"LatihanDB");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

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


function getData()
    $data = array();
    $data[1] = $_POST['nama'];
    $data[2] = $_POST['nim'];
    return $data;

if (isset($_POST['insert'])) {
    $info = getData();
    $insert = "INSERT INTO [tbl_mahasiswa] ([id]
        ,[nim]) VALUES ('$info[1]','$info[2]')";
    $result = odbc_exec($conn, $insert);

<!DOCTYPE html>
<html lang="en">

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>


    <div class="jumbotron text-center">
        <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Alias eius illum non.!</p>

        <form method="POST">
            <div class="form-group">
                <label for="nama">Nama:</label>
                <input type="text" class="form-control" id="nama" name="nama">
            <div class="form-group">
                <label for="nim">NIM:</label>
                <input type="text" class="form-control" id="nim" name="nim">
            <button type="submit" class="btn btn-warning" style="color: #fff;" name="insert">Submit</button>


Outputnya :
Screenshot-83.pngScreenshot (83).png 90.07 KB
avatar HendryScootKennedy


19 Kontribusi 0 Poin


Belum ada Jawaban, jadi yang pertama

Login untuk gabung berdiskusi