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!
CREATE TABLE `sales` (
`SaleID` int(5) NOT NULL auto_increment,
`Title` varchar(255) NOT NULL default '',
`Image_Ref` varchar(255) NOT NULL default '',
`Description` text NOT NULL,
`Date` date NOT NULL default '0000-00-00',
PRIMARY KEY (`SaleID`),
FULLTEXT KEY `Description` (`Description`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;
I want to have a form in which i can fill in the fields for the database table above. And also select a picture to upload to a directory and automaticlly add a reference to the table (ive been told this is better than storing the image inside the table itself). I want it so when the image is uploaded to the directory the image reference is added to the database and the image name is changed to the specific row ID of the table.
How would i do this, can anyone help me because im stuck?
Thanks alot
Jim
feyd | please use formatting tags when posting code
Basiclly i have made the table structure (table name = sales) above and made the table in the mysql database (db name = gbplat).
Now im stuck on howto have an upload page that uploads an image into a directory on the server and adds a reference to the database for the image thats just been uploaded, so that the image dosnt have to be stored inside the database as binary data. Also i dont know howto make the image name change to the specific row ID when its uploaded. For example, SaleID 5, i would like the image name auto changed to
SaleImage-5, SaleID 6 i would like the image name changed to
SaleImage-6 and so on. And at the same time add a reference to the database table field Image_Ref to link to the uploaded image.
How would i go about doing this.
Im fairly new to databases, so any help would be greatly appriciated.
there have been a lot of threads here on file upload handling, this may help too.
as for renaming the file, during the call to move_uploaded_file() you can rename it to whatever you wish. To retrieve the id used for the user row, last_insert_id() can return that.
You may want to consider increasing the size of the SaleID field.