JavaScript
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result)
.width(150)
.height(200);
};
reader.readAsDataURL(input.files[0]);
}
}
</script>
PHP
if($_POST) {
$image = $_POST["image"];
$pro_name = $_POST["pro_name"];
$pro_desc = $_POST["pro_desc"];
$price = $_POST["price"];
$categories = $_POST["categories"];
$stock = $_POST["stock"];
$ekle=mysql_query("insert into product (`product_id`,`pro_name`,`pro_desc`,`price`,`categories`,`image`,`stock`)
VALUES (NULL, '$pro_name','$pro_desc','$price','$categories','$image','$stock')");
if($ekle) {
echo "<script>alert('Product Added Succecfully.');window.location='add_pro.php'</script>";
} else {
echo "<script>alert('Unexpected Error, plase try again.');window.location='add_pro.php'</script>";
}
}
HTML
<td width="175" height="225"><img id="blah" src="#" alt="your image" /></td>
<td><input type='file' onchange="readURL(this);" name="image" value=""/></td>
This HTML part shows the image on page, I need to take the image URL and send it to the database but I don't know how to do this in JavaScript.