Updating Image from database to root folder

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

lesterdgreat123
Forum Newbie
Posts: 10
Joined: Thu Nov 03, 2011 10:35 am

Updating Image from database to root folder

Post 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>
Last edited by lesterdgreat123 on Fri Nov 04, 2011 11:08 am, edited 1 time in total.
lesterdgreat123
Forum Newbie
Posts: 10
Joined: Thu Nov 03, 2011 10:35 am

Re: Updating Image from database to root folder

Post by lesterdgreat123 »

Please guys help me on this?
lesterdgreat123
Forum Newbie
Posts: 10
Joined: Thu Nov 03, 2011 10:35 am

Re: Updating Image from database to root folder

Post 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!!!!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Updating Image from database to root folder

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
lesterdgreat123
Forum Newbie
Posts: 10
Joined: Thu Nov 03, 2011 10:35 am

Re: Updating Image from database to root folder

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Updating Image from database to root folder

Post by pickle »

It's a joke. Don't get rude because you didn't get the answer you wanted.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
lesterdgreat123
Forum Newbie
Posts: 10
Joined: Thu Nov 03, 2011 10:35 am

Re: Updating Image from database to root folder

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Updating Image from database to root folder

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
lesterdgreat123
Forum Newbie
Posts: 10
Joined: Thu Nov 03, 2011 10:35 am

Re: Updating Image from database to root folder

Post by lesterdgreat123 »

i had already put a comment, please help me.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Updating Image from database to root folder

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
lesterdgreat123
Forum Newbie
Posts: 10
Joined: Thu Nov 03, 2011 10:35 am

Re: Updating Image from database to root folder

Post 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
lesterdgreat123
Forum Newbie
Posts: 10
Joined: Thu Nov 03, 2011 10:35 am

Re: Updating Image from database to root folder

Post 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'];
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Updating Image from database to root folder

Post by pickle »

That's a select query. It won't change anything.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
lesterdgreat123
Forum Newbie
Posts: 10
Joined: Thu Nov 03, 2011 10:35 am

Re: Updating Image from database to root folder

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Updating Image from database to root folder

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply