Error in insertion
Posted: Wed Jun 09, 2010 8:16 am
My database connection is SQL Server .I have created one Table name as Webimages . Database field is image_content - datatype is image. When i am use below query to upload the images into sql server . I am getting error message .
Any Suggestion Please ??????
Code: Select all
Connection established. Row insertion failed. Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Server Native Client 10.0]Syntax error, permission violation, or other nonspecific error [message] => [Microsoft][SQL Server Native Client 10.0]Syntax error, permission violation, or other nonspecific error ) )
Code: Select all
<?php
$uid = "username";
$pwd = "password";
$serverName = "servername";
$connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=>"databasename");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn )
{
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
if($_POST['submit']){
move_uploaded_file($_FILES['image']['tmp_name'],"latest.img");
$instr = fopen("latest.img","rb");
$image = addslashes(fread($instr,filesize("latest.img")));
$query = "INSERT INTO Webimages(image_content)values('$image')";
$stmt = sqlsrv_prepare($conn,$query);
if( $stmt )
{
echo "Row successfully inserted.\n";
}
else
{
echo "Row insertion failed.\n";
die( print_r( sqlsrv_errors(), true));
}
}
?>
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="image" id="image" />
<input type="submit" name="submit" value="Submit" />
</form>