Retrieving an image path from the database for editing.

  • (2 Pages)
  • +
  • 1
  • 2

26 Replies - 11979 Views - Last Post: 29 August 2011 - 01:29 AM Rate Topic: -----

#16 chukwuemmanuel09  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 60
  • Joined: 18-August 11

Re: Retrieving an image path from the database for editing.

Posted 19 August 2011 - 04:53 AM

Hey Pal...Thx for the idea.I have successed in doing that part but the code is not updating..can u help me take a look at it..Please
<?php

//Inialize session
session_start();

//Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['User_name'])) 
{
   header('Location: main.php');
   exit();
}


//Connect my database.
include "database.php";

//Pass the session value to the variable $Property_id
$Property_id = $_SESSION['property_id'];

//This gets all the other information from the form
$agent_sessionId = $_SESSION['agent_id'];
$Property_Type=$_POST['Property_Type'];
$Property_Category=$_POST['Property_Category'];
$Property_Description=$_POST['Property_Description'];
$Address=$_POST['Address'];
$Street=$_POST['Street'];
$Town=$_POST['Town'];
$State=$_POST['State'];
$Country=$_POST['Country'];
$Date = date("Y-m-d");
$Property_Price=$_POST['Property_Price'];
$Number_Of_Rooms=$_POST['Number_Of_Rooms'];
$Number_Of_Bathrooms=$_POST['Number_Of_Bathrooms'];
//get the file name
$picture = $_FILES['file']['name'];



//check the type of the image.
$imageinfo = getimagesize($_FILES["file"]["tmp_name"]);

if ($imageinfo ['mime'] != 'image/gif' && $imageinfo ['mime'] != 'image/jpeg'
&& $imageinfo ['mime'] != 'image/pjpeg' && $imageinfo ['mime'] != 'image/jpg'
&& $imageinfo ['mime'] != 'image/png')
{
echo "sry Image not supported";
exit;
}




/*
script to echo out the name of the file,its type, size
and name of the temporary copy of the place where the file
is stored in the server.*/

if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "
";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "";
echo "Type: " . $_FILES["file"]["type"] . "";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "";



if (file_exists("Images/properties/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],"Images/properties/" . $_FILES["file"]["name"]);

sql ="UPDATE Property_Details SET 
                                       'Property_Id' = "",
                                       'Agent_Id' = '$agent_sessionId',
                                       'Property_Type'= '$Property_Type',
                                       'Property_Category'= '$Property_Category',
                                       'Property_Description'= '$Property_Description',
                                       'Address'= '$Address',
                                       'Street' = '$Street',
                                       'Town' = '$Town',
                                       'State' = '$State',
                                       'Country' = '$Country',
                                       'Date' = '$Date',
                                       'Property_Price' = '$Property_Price',
                                       'Number_Of_Rooms' = '$Number_Of_Rooms',
                                       'Number_Of_Bathrooms'= '$Number_Of_Bathrooms',
                                       'Img1'= '$picture' WHERE 'Property_Id' = '$Property_id'";


			mysql_query($sql) or die ("Error: ".mysql_error());
			
			echo "Database updated.";

}
}


?>


This post has been edited by macosxnerd101: 19 August 2011 - 06:44 AM
Reason for edit:: CODE TAGS!!! USE THEM!!!

Was This Post Helpful? 0
  • +
  • -

#17 Syfer  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 190
  • Joined: 08-October 10

Re: Retrieving an image path from the database for editing.

Posted 19 August 2011 - 05:03 AM

They already posted the hints/answers to your problem but yet you can't get through ,
analyze what they are saying and you won't ask for further questions.
Was This Post Helpful? 0
  • +
  • -

#18 chukwuemmanuel09  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 60
  • Joined: 18-August 11

Re: Retrieving an image path from the database for editing.

Posted 19 August 2011 - 05:11 AM

Hey Pal..U guys where once starter like me..so just take it easy on me okay...
You were once like me at a stage..
Was This Post Helpful? -4
  • +
  • -

#19 chukwuemmanuel09  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 60
  • Joined: 18-August 11

Re: Retrieving an image path from the database for editing.

Posted 19 August 2011 - 05:23 AM

All i need if for someone to tell me whats wrong with the update part of my query.
Was This Post Helpful? 0
  • +
  • -

#20 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Retrieving an image path from the database for editing.

Posted 19 August 2011 - 05:28 AM

No, we would listen to what we're told, I told you 4x that you cannot set a value of an <input type="file" .. /> element, yet 4x you asked it. We were never like that I can almost guarantee that to you.

If it's not updated, look at the error.
Was This Post Helpful? 0
  • +
  • -

#21 chukwuemmanuel09  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 60
  • Joined: 18-August 11

Re: Retrieving an image path from the database for editing.

Posted 19 August 2011 - 05:34 AM

Ok. I got that point but i have been able to insert into the database with exactly the same thing. More so i have outputted all my variable on the update page and everything is ok. But is just not inserting and there is no error showing.

Check this link. they did the same thing http://www.w3schools...file_upload.asp
Was This Post Helpful? 0
  • +
  • -

#22 chukwuemmanuel09  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 60
  • Joined: 18-August 11

Re: Retrieving an image path from the database for editing.

Posted 19 August 2011 - 05:50 AM

More Links that still did the same thing: http://www.youtube.c...e=youtube_gdata

This post has been edited by chukwuemmanuel09: 19 August 2011 - 05:50 AM

Was This Post Helpful? 0
  • +
  • -

#23 Ace26  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 183
  • Joined: 10-August 08

Re: Retrieving an image path from the database for editing.

Posted 19 August 2011 - 06:11 AM


<?php

//Removed column Property_Id from the update command
sql ="UPDATE Property_Details SET 
                                       'Agent_Id' = '$agent_sessionId',
                                       'Property_Type'= '$Property_Type',
                                       'Property_Category'= '$Property_Category',
                                       'Property_Description'= '$Property_Description',
                                       'Address'= '$Address',
                                       'Street' = '$Street',
                                       'Town' = '$Town',
                                       'State' = '$State',
                                       'Country' = '$Country',
                                       'Date' = '$Date',
                                       'Property_Price' = '$Property_Price',
                                       'Number_Of_Rooms' = '$Number_Of_Rooms',
                                       'Number_Of_Bathrooms'= '$Number_Of_Bathrooms',
                                       'Img1'= '$picture' WHERE 'Property_Id' = '$Property_id'";


			mysql_query($sql) or die ("Error: ".mysql_error());
			
			echo "Database updated.";

}
}


?>



First of all, remove the single quotes around the table columns you are wanting to update in your update command.

Secondly, you'll notice that I removed the Property_Id column from the update command cause you were trying to update it while using it to qualify your Update operation in the WHERE clause. That's wrong and error prone.
For that column(Property_Id and similar ones in other tables), when creating your tables, have the database increment that automatically for you when ever someone inserts a new record using the AUTO_INCREMENT directive in your column definition.

Finally, when you are posting in the forums always enclose you code in code tags as it helps readability alot. Also take out time to thoroughly study and improve your knowledge on PHP and SQL(MySQL) respectively and you'll do just fine.

This post has been edited by Ace26: 19 August 2011 - 06:13 AM

Was This Post Helpful? 2
  • +
  • -

#24 chukwuemmanuel09  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 60
  • Joined: 18-August 11

Re: Retrieving an image path from the database for editing.

Posted 19 August 2011 - 06:15 AM

Thx Ace26 for the idea...This was really helpful.
Was This Post Helpful? 0
  • +
  • -

#25 chukwuemmanuel09  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 60
  • Joined: 18-August 11

Re: Retrieving an image path from the database for editing.

Posted 19 August 2011 - 12:04 PM

@Ace26..thx a lot..you idea was perfect.I am so hapi we have people like u in here.
Was This Post Helpful? -1
  • +
  • -

#26 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5346
  • View blog
  • Posts: 27,301
  • Joined: 10-May 07

Re: Retrieving an image path from the database for editing.

Posted 28 August 2011 - 07:10 PM

View Postchukwuemmanuel09, on 19 August 2011 - 08:11 AM, said:

You were once like me at a stage..

The problem is you can't just copy & paste a solution, & then reply : Didn't work

We may as well be doing it for you, & all you are doing is walking away with a provided solution, not an understanding.
Was This Post Helpful? 0
  • +
  • -

#27 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 795
  • View blog
  • Posts: 1,681
  • Joined: 30-January 09

Re: Retrieving an image path from the database for editing.

Posted 29 August 2011 - 01:29 AM

View PostJackOfAllTrades, on 19 August 2011 - 05:50 AM, said:

Just another help vampire.

+1
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2