Jump to content

Saving image to mysql, help needed


Recommended Posts



I am trying to save image in mysql table using blob. I am show you my code [form page and backend page for insertion], please let me know where i am wrong ?

<!DOCTYPE html>
    <link href="css/kendo.metro.min.css"rel="stylesheet"> 
        <link href="css/kendo.common.min.css" rel="stylesheet">
        <script src="js/jquery.min.js"></script>
        <script src="js/kendo.web.min.js"></script>
		<script src="js/kendo.upload.min.js"></script>
		<script type="text/javascript">

				type: "POST",
				url: 'data/create_new_property.php',
				data: "buildername=" + $('#buildername').val() + "&projectname=" + $('#projectname').val() +  "&files=" + $('#files').val(),
				success: function(data){
    <div id="example" class="k-content">
        <ul class="forms">
                <input type="text" class="k-textbox" id="buildername" value="Builder Name" 
				onblur="if (this.value == '') {this.value = 'Builder Name';}"
 onfocus="if (this.value == 'Builder Name') {this.value = '';}"/>
                <input type="text" class="k-textbox" id="projectname" value="Project Name" 
				onblur="if (this.value == '') {this.value = 'Project Name';}"
 onfocus="if (this.value == 'Project Name') {this.value = '';}"/>
			 <input type="text" class="k-textbox" id="location" value="Location" 
				onblur="if (this.value == '') {this.value = 'Location';}"
 onfocus="if (this.value == 'Location') {this.value = '';}"/>
			 <input type="text" class="k-textbox" id="budget" value="Budget" 
				onblur="if (this.value == '') {this.value = 'Budget';}"
 onfocus="if (this.value == 'Budget') {this.value = '';}"/>
			 <input type="text" class="k-textbox" id="propertytype" value="Property Type" 
				onblur="if (this.value == '') {this.value = 'Property Type';}"
 onfocus="if (this.value == 'Property Type') {this.value = '';}"/>
			<input name="files" id="files" type="file" />
			 <input type="text" class="k-textbox" id="area" value="Area" 
				onblur="if (this.value == '') {this.value = 'Area';}"
 onfocus="if (this.value == 'Area') {this.value = '';}"/>
                <button class="k-button" id="btnSubmit">Save Project</button>
        <style scoped>
            .forms {
                float: left;

            .forms li {
                margin-bottom: 5px;
                list-style: none;

            .forms li > * {
                width: 400px;


php code to Insert data in mysql

header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: POST, GET");
header("Access-Control-Allow-Headers: x-requested-with");

mysql_connect("localhost", "root", "") or die("Connection Failed");
mysql_select_db("property")or die("Connection Failed");

$bname = $_POST['buildername'];
$pname = $_POST['projectname'];
$uploadfiles = addslashes (file_get_contents($_FILES['files']['tmp_name']));

$image = getimagesize($_FILES['files']['tmp_name']);//to know about image type etc
$imgtype = $image['mime'];
//$query = "UPDATE test SET password = '$password' WHERE name = '$user'";

$query = "INSERT INTO projects (buildername, projectname, img) VALUES('$bname','$pname','$uploadfiles')";
echo "updated";}
echo "fail";}


Please correct me where i am wrong.


Thanks a lot for your time

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.