Updating Image from database to root folder
Posted: Thu Nov 03, 2011 10:45 am
Guys, i really need your help me to my code, im really having a deadline this coming satruday. Anyway, i ask for your help for my code i dont know how to continue this code for updating the image, im so confuse. I hope you can help me. here is my code.
<?php
session_start();
include('../../dbcon.php');
//this variables are from the form of the updateProduct.php
$uid = $_SESSION['userID'];
$id = $_POST['pid'];
$prodName = $_POST['prod'];
$price = $_POST['price'];
$desc = $_POST['des'];
$village = $_POST['village'];
$zip = $_POST['zip'];
$company = $_POST['company'];
$hours = $_POST['hours'];
$cat = $_POST['cat'];
$fileName=$_POST['filename'];
if($_FILES['upload']['type'] != "image/jpeg") {//This will verify if the image is jpeg
echo '
<script type="text/javascript">
alert("Invalid Upload!");
location = "../updateProduct.php";
</script>
';
}elseif(is_uploaded_file($_FILES['upload']['tmp_name'])) {
// it will get the product id of the product
$res = mysql_query("SELECT * FROM `product` WHERE product.pid=".$id);
$r = mysql_fetch_array($res);
$fileName=$r['filename'];
//Path for the image from the root directory folder
$path= '../images/products/';
$folder='../images/products/';
if (!file_exists($path)) {
mkdir('../images/');
}
if (!file_exists($folder)){
mkdir('../images/products/');
}
move_uploaded_file($_FILES['upload']['tmp_name'], $folder.$fileName);
}else{
echo '
<script type="text/javascript">
alert("ERROR Upload!");
location = "../updateProduct.php";
</script>
';
}
// Is my query correct?????
$query = "UPDATE product
SET
userID = '$uid', prodName='$prodName', price = '$price', company = '$company', description = '$desc', hours = '$hours', catid ='$cat', filename = '$fileName', location = '$village', zipcode='$zip'
WHERE
pid=$id";
$result = @mysql_query($query);
if($result){
echo '
<script type="text/javascript">
alert("You have already updated your product! - '.$fileName.'");
location = "../updateProduct.php";
</script>
';
}
else
{
echo'not inserted';
echo $id;
}
?>
</div>
</div>
</body>
</html>
<?php
session_start();
include('../../dbcon.php');
//this variables are from the form of the updateProduct.php
$uid = $_SESSION['userID'];
$id = $_POST['pid'];
$prodName = $_POST['prod'];
$price = $_POST['price'];
$desc = $_POST['des'];
$village = $_POST['village'];
$zip = $_POST['zip'];
$company = $_POST['company'];
$hours = $_POST['hours'];
$cat = $_POST['cat'];
$fileName=$_POST['filename'];
if($_FILES['upload']['type'] != "image/jpeg") {//This will verify if the image is jpeg
echo '
<script type="text/javascript">
alert("Invalid Upload!");
location = "../updateProduct.php";
</script>
';
}elseif(is_uploaded_file($_FILES['upload']['tmp_name'])) {
// it will get the product id of the product
$res = mysql_query("SELECT * FROM `product` WHERE product.pid=".$id);
$r = mysql_fetch_array($res);
$fileName=$r['filename'];
//Path for the image from the root directory folder
$path= '../images/products/';
$folder='../images/products/';
if (!file_exists($path)) {
mkdir('../images/');
}
if (!file_exists($folder)){
mkdir('../images/products/');
}
move_uploaded_file($_FILES['upload']['tmp_name'], $folder.$fileName);
}else{
echo '
<script type="text/javascript">
alert("ERROR Upload!");
location = "../updateProduct.php";
</script>
';
}
// Is my query correct?????
$query = "UPDATE product
SET
userID = '$uid', prodName='$prodName', price = '$price', company = '$company', description = '$desc', hours = '$hours', catid ='$cat', filename = '$fileName', location = '$village', zipcode='$zip'
WHERE
pid=$id";
$result = @mysql_query($query);
if($result){
echo '
<script type="text/javascript">
alert("You have already updated your product! - '.$fileName.'");
location = "../updateProduct.php";
</script>
';
}
else
{
echo'not inserted';
echo $id;
}
?>
</div>
</div>
</body>
</html>