7 Replies - 399 Views - Last Post: 18 April 2013 - 04:38 AM Rate Topic: -----

#1 istore221  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 136
  • Joined: 11-December 11

Save image with the name of current auto_increment value.jpg

Posted 17 April 2013 - 04:25 AM

Hi..i want to do something like this in my web site user can upload movie poster when they upload along with the movie title and released year in my database i keep track on the posters like this

Movie_Covers/8.jpg
Movie_Covers/9.jpg

this digit is the primary key of the movie

but in my this case when user upload a movie how can i auto Genarate the image and the real problem is i also move the uploaded image to Movie_Covers folder
so far
	mysql_query("INSERT INTO movies(UploaderID,CatID,Title,Year,ImageURL,ImdbURL,Addeddate)
			VALUES('".$uploader."','".$Type."','".$Title."',$Year,'Movie_Covers/MY_AUTO_INCREMENT_VALUE.jpg','".$imdburl."','".$uploadedate."')",$con) 
			or die ("Query Error Occured");




note Movie_Covers/MY_AUTO_INCREMENT_VALUE.jpg this is where i want my current auto_increment number to apper but i don't have a clue to do this.

Is This A Good Question/Topic? 0
  • +

Replies To: Save image with the name of current auto_increment value.jpg

#2 Slice  Icon User is offline

  • sudo pacman -S moneyz


Reputation: 245
  • View blog
  • Posts: 719
  • Joined: 24-November 08

Re: Save image with the name of current auto_increment value.jpg

Posted 17 April 2013 - 05:24 AM

As far as I know you can't change the name of a file during the query, this would have to be done with php (as far as i know, if it is possible i'm sure someone will correct me.).

First I would query to see what the latest entry is, explode it to find the number and then simply add 1 to the value.
Was This Post Helpful? 0
  • +
  • -

#3 istore221  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 136
  • Joined: 11-December 11

Re: Save image with the name of current auto_increment value.jpg

Posted 17 April 2013 - 05:30 AM

in that case what will happen when some one add a another movie before insert my query in that case my latest value i took is wrong ..nah ?

This post has been edited by Dormilich: 17 April 2013 - 12:11 PM

Was This Post Helpful? 0
  • +
  • -

#4 Slice  Icon User is offline

  • sudo pacman -S moneyz


Reputation: 245
  • View blog
  • Posts: 719
  • Joined: 24-November 08

Re: Save image with the name of current auto_increment value.jpg

Posted 17 April 2013 - 05:49 AM

How many people do you expect to be using your website? It takes about half a second to run through a function that could easily fetch information, explode into array, increment it, and upload.
Was This Post Helpful? 0
  • +
  • -

#5 istore221  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 136
  • Joined: 11-December 11

Re: Save image with the name of current auto_increment value.jpg

Posted 17 April 2013 - 06:16 AM

lest say 100 users if it is ok i do like that . will it overlap with other transations

This post has been edited by Dormilich: 17 April 2013 - 12:11 PM

Was This Post Helpful? 0
  • +
  • -

#6 e_i_pi  Icon User is offline

  • = -1
  • member icon

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

Re: Save image with the name of current auto_increment value.jpg

Posted 17 April 2013 - 02:41 PM

I use something like this on my website, in that people save files to the file system while a row is added to a database table which stores specific file information. You don't need to store the URL during INSERT, you build it during your SELECT, like so:
SELECT
  ID,
  CONCAT('Movie_Covers/', CAST(ID AS CHAR), '.jpg') AS ImageURL,
  ImdbURL
FROM movies


This post has been edited by e_i_pi: 17 April 2013 - 02:42 PM

Was This Post Helpful? 1
  • +
  • -

#7 istore221  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 136
  • Joined: 11-December 11

Re: Save image with the name of current auto_increment value.jpg

Posted 17 April 2013 - 07:40 PM

View Poste_i_pi, on 17 April 2013 - 02:41 PM, said:

I use something like this on my website, in that people save files to the file system while a row is added to a database table which stores specific file information. You don't need to store the URL during INSERT, you build it during your SELECT, like so:
SELECT
  ID,
  CONCAT('Movie_Covers/', CAST(ID AS CHAR), '.jpg') AS ImageURL,
  ImdbURL
FROM movies



I can get your point . but having this all things done how do i rename and move the uploaded file with the name of Movie primary key ?
Was This Post Helpful? 0
  • +
  • -

#8 e_i_pi  Icon User is offline

  • = -1
  • member icon

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

Re: Save image with the name of current auto_increment value.jpg

Posted 18 April 2013 - 04:38 AM

When you insert a record into the database, you can get the last insert ID as the return value. It differs depending on the DB server you are using. Assuming you are using MySQL, and that you are using mysql_* PHP functions, then immediately after you run the mysql_query() to insert, run the PHP function mysql_insert_id.

I might add, you shouldn't be using the mysql_* functions - they are deprecated, open to security issues, and you should look into Prepared Statements and PDOs instead. Resident mentor Dormilich has written two excellent tutorials here and here. If they are too moch to get your head around, you could use mysqli_* functions in the meantime, but I strongly suggest moving to PS/PDO for DB access.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1