klapsius
klapsius

Reputation: 75

INSERT INTO problems

I'm trying to do simple operation but i have 2 problems. 1. Script not working: html file

<input type="text" name="traceability" id="traceability_1" maxlength="8" />
<input type="password" name="operator" id="operator"/>
$sql="INSERT INTO x_23_5_14 ( traceability, operator)VALUES
('$_POST[traceability]', '$_POST[operator]' )";
if (!sqlsrv_query($conn,$sql)){
print('Error');
 echo"   ".sqlsrv_errors() ."\n";
} else {
echo "1 record added";
}  
  1. Why ".sqlsrv_errors() always return array?

Upvotes: 0

Views: 94

Answers (1)

drdystopie
drdystopie

Reputation: 28

You can try this :

$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 />";
        }
    }
}

Upvotes: 1

Related Questions