我正在尝试通过Ajax插入图像。 但是查询没有被执行

Image is not getting inserted in mysql. From Ajax FAIL response is coming.

code is given below

<?php
include "db.php";

 //keep your db name
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
//you keep your column name setting for insertion. I keep image type Blob.
$query = "INSERT INTO images (id,image) VALUES(0,'$image')";  
$qry = mysqli_query($con,$query);
if($qry){
    echo "success";
}else{
    echo "fail";
}
?>
<html lang="en">
<head>
<title>PHP - Image Uploading with Form JS Example</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" >
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
<script src="http://malsup.github.com/jquery.form.js"></script> 
<script> 
        $(document).ready(function() { 
            $(".upload-image").click(function(){
                $(".form-horizontal").ajaxForm({target: '.preview'}).submit();
            });
        }); 
</script>
</head>
<body>
    <nav class="navbar navbar-default">
        <div class="container-fluid">
        <div class="navbar-header">
        <a class="navbar-brand" href="#">PHP - Image Uploading with Form JS Example</a>
        </div>
        </div>
    </nav>
    <div class="container">
    <form action="ajax_php_file.php" enctype="multipart/form-data" class="form-horizontal" method="post">
        <div class="preview"></div>
        <input type="file" name="image" class="form-control" style="width:30%" />
        <button class="btn btn-primary upload-image">Save</button>
    </form>
    </div>
</body>
</html>

The table==== here it is the table

DROP TABLE IF EXISTS live_your_life.images; CREATE TABLE live_your_life.images ( id int(10) unsigned NOT NULL DEFAULT '0', image blob, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Any help will be appreciated!!

</div>

You should add auto increment to your primary key in table I would not recommend you to insert images into databases, but if you insist to insert the images into database you should make sure that the images is uploaded into your workspace first, ex: path/upload/

Then when you do insert you can use

LOAD_FILE('/some/path/image.png')

ex : INSERT INTO table_name (ID,IMAGE) VALUES(1,LOAD_FILE('your upload path'));

note: it will be good if you upload then images in the workspace path, then you saves the path in the database, so when you need the images, you can load it from your workspace folder not from your database

sorry for bad english