Page 1 of 2

Updating Image from database to root folder

Posted: Thu Nov 03, 2011 10:45 am
by lesterdgreat123
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>

Re: Updating Image from database to root folder

Posted: Thu Nov 03, 2011 7:17 pm
by lesterdgreat123
Please guys help me on this?

Re: Updating Image from database to root folder

Posted: Fri Nov 04, 2011 10:35 am
by lesterdgreat123
THANK YOU GUYS FOR NOT GIVING COMMENTS ON THIS, ANYWAY, MY DEADLINE WILL BE IN 1 HOUR,. I REALLY APPRECIATE THAT THIS SITE IS VERY ACTIVE!!!!

Re: Updating Image from database to root folder

Posted: Fri Nov 04, 2011 10:45 am
by pickle
You dumped all your code rather than the relevant sections, didn't format your code, didn't really explain your problem, didn't show any evidence of trying to fix your problem (ie: "I tried doing this..."), bumped your topic within 24 hours - and you expect us to take our time to help you? The Internet isn't a magic solution machine - you've got to put effort in yourself.

Re: Updating Image from database to root folder

Posted: Fri Nov 04, 2011 10:49 am
by lesterdgreat123
"Real programmers don't comment their code. If it was hard to write, it should be hard to understand"??

Really? it doesnt matter if you comment or not, if you really want to help then help, or maybe you just dont know it that why.

Re: Updating Image from database to root folder

Posted: Fri Nov 04, 2011 10:53 am
by pickle
It's a joke. Don't get rude because you didn't get the answer you wanted.

Re: Updating Image from database to root folder

Posted: Fri Nov 04, 2011 10:56 am
by lesterdgreat123
come on men, i really need a help right now, im loosing hope, please? here it is, i tried to upload image but it doesn't update the image but it return a null status on the database, is my code correct? if you really want to help me please help me?

Re: Updating Image from database to root folder

Posted: Fri Nov 04, 2011 11:02 am
by pickle
lesterdgreat123 wrote:but it return a null status on the database
I don't understand what this means. Also - please edit your original post & wrap your code in proper tags - clicking the "PHP Code" will show you the necessary tags.

Re: Updating Image from database to root folder

Posted: Fri Nov 04, 2011 11:09 am
by lesterdgreat123
i had already put a comment, please help me.

Re: Updating Image from database to root folder

Posted: Fri Nov 04, 2011 11:14 am
by pickle
Your query is syntactically correct. I'd take out the @ on mysql_query - in case it's generating a helpful error. Also echo the query and run it manually, to see if a) the query looks like you expect and b) if it does what you expect.

Re: Updating Image from database to root folder

Posted: Fri Nov 04, 2011 11:20 am
by lesterdgreat123
thank you for that, can i add you at skype or yahoo messenger so that i can chat with you in real time so that you can really guide me, because its my first time to do this concept. here is my
skype: lesterwebservices
Yahoo messenger: lesterdgreat123

Re: Updating Image from database to root folder

Posted: Fri Nov 04, 2011 11:29 am
by lesterdgreat123
is there a problem on this code because it can not change the filename of the image

$res = mysql_query("SELECT * FROM `product` WHERE product.pid=".$id);
$r = mysql_fetch_array($res);
$fileName=$r['filename'];

Re: Updating Image from database to root folder

Posted: Fri Nov 04, 2011 11:31 am
by pickle
That's a select query. It won't change anything.

Re: Updating Image from database to root folder

Posted: Fri Nov 04, 2011 11:34 am
by lesterdgreat123
can you guide me, its been two night i've been figuring this out looking for other forums or tutorials that would help me. can you hand you knowledge and teach me what to do? it will help me a lot really, my deadline will be in a few a hours, please?

Re: Updating Image from database to root folder

Posted: Fri Nov 04, 2011 11:42 am
by pickle
Sorry no. It sounds like you don't really know what you're doing - even enough to properly explain your problem. That's not meant as an insult - just an observation that it seems you're not very experienced. It will be pretty much impossible to solve the problem in the short time you have.