newb Posted August 11, 2006 Share Posted August 11, 2006 i want the file name to be renamed to the same as the id number thats auto_generated in the database but its not!.[code]<?php if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) { // success!include "dbconfig.php"; $query = mysql_query("SELECT * FROM `style_imgupload` ORDER BY id ASC LIMIT 2"); $row = mysql_fetch_array($query); $uid = $row['id']; rename("styles/$file_name", "styles/$uid$ext"); echo "File $i: ($uid$ext) Uploaded.<br>"; }else{ echo "File $i: Faild to upload.<br>"; }#end of (move_uploaded_file). }#end of (file_exists). }#end of (file_size). }#end of (limitedext). }#end of (!is_uploaded_file). }#end of (for loop). $id = mysql_insert_id(); $insert = mysql_query("INSERT INTO style_imgupload (id, active, author, author_url, ip_address) VALUES ('$id', '$active', '$author', '$author_url', '$ip_address')"); if (!$insert) { die('Invalid query: ' . mysql_error());}?>[/code]whenever i submit information it doesnt rename to the same id as whats generated in the database. please help! Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/ Share on other sites More sharing options...
KittyKate Posted August 11, 2006 Share Posted August 11, 2006 Try "SELECT MAX(ID) as ID ..." and increment it by one (id++;) before re-uploading. I haven't looked close enough to figure out why you are getting two rows, but this should be a start. Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73353 Share on other sites More sharing options...
newb Posted August 12, 2006 Author Share Posted August 12, 2006 didnt help Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73538 Share on other sites More sharing options...
newb Posted August 12, 2006 Author Share Posted August 12, 2006 someone pleasee help!111 Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73543 Share on other sites More sharing options...
newb Posted August 12, 2006 Author Share Posted August 12, 2006 ok i fixed the mysql database problem, but whenever i submit something it doesnt rename to the same id as whats in the database. i want the file name to be renamed to the same as the id number thats auto_generated in the database but its not!. please help! Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73552 Share on other sites More sharing options...
newb Posted August 12, 2006 Author Share Posted August 12, 2006 ur code didnt help. Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73555 Share on other sites More sharing options...
hostfreak Posted August 12, 2006 Share Posted August 12, 2006 Sorry, I totally mis-understood your question. A bit late here. Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73556 Share on other sites More sharing options...
newb Posted August 12, 2006 Author Share Posted August 12, 2006 its ok, can you help me please?? i am prety newbie here =[ Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73557 Share on other sites More sharing options...
hostfreak Posted August 12, 2006 Share Posted August 12, 2006 What exactly does it rename the file name to? Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73558 Share on other sites More sharing options...
newb Posted August 12, 2006 Author Share Posted August 12, 2006 well, its suppose to rename the file to the next number. kinda like auto_incrementing on tables in sql. here's my sql table:[img]http://www.flickcabin.com/sessions/306f2f2b636bb59e1cf9d7d43b71c978a1eed72c/table.PNG[/img]whenever i upload a file, its suppose to rename that file to the exact id number as whats in the id field on that table, but its not doing that :(.however, whenever i upload something or a file, it inserts the data into the table just fine, but it doesnt rename the file to the same id number as in the table, it just renames it to something else. Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73560 Share on other sites More sharing options...
hostfreak Posted August 12, 2006 Share Posted August 12, 2006 Yeah, I am curious what it does rename it to? Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73561 Share on other sites More sharing options...
newb Posted August 12, 2006 Author Share Posted August 12, 2006 eh i just told you in the post above. its suppose to rename the file to the exact id number as whats being generated in the id field on that table whenever i hit the submit button to upload something. Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73563 Share on other sites More sharing options...
hostfreak Posted August 12, 2006 Share Posted August 12, 2006 I am aware of what it is suposed to do, I would like to know what it is actually doing though. So instead of renaming it to the id like it is suposed to, what is it actually renaming it to? You say "something else", what exactly is that something else? Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73564 Share on other sites More sharing options...
newb Posted August 12, 2006 Author Share Posted August 12, 2006 it just renames them to 1.jpg, im assuming it does that because thats the id number in the first row. im fully aware my code is this:[code=php:0]$uid = $row['id'];rename("styles/$file_name", "styles/$uid$ext"); [/code]im guessing thats why it does that. however, i dont want it to rename a file to 1.jpg each time i upload something, and thats what its doing. is there a way to fix it??? any one can help?? Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73566 Share on other sites More sharing options...
newb Posted August 12, 2006 Author Share Posted August 12, 2006 pls? Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73568 Share on other sites More sharing options...
Chetan Posted August 12, 2006 Share Posted August 12, 2006 Use this the first time when you select data, order it by id descending and limit it to 1.when renaming set the file name to the resulted id +1.That meansChange$query = mysql_query("SELECT * FROM `style_imgupload` ORDER BY id ASC LIMIT 2")to$query = mysql_query("SELECT * FROM `style_imgupload` ORDER BY id DESC LIMIT 0, 1")andrename("styles/$file_name", "styles/$uid$ext"); to$uida = $uid+1;rename("styles/$file_name", "styles/$uida$ext"); Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73605 Share on other sites More sharing options...
newb Posted August 12, 2006 Author Share Posted August 12, 2006 works! thanks a bunch dude!!1 i was starting to give up on here =[ Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73781 Share on other sites More sharing options...
Chetan Posted August 12, 2006 Share Posted August 12, 2006 Well thanks for the big thank you Link to comment https://forums.phpfreaks.com/topic/17286-need-help-with-sql-upload/#findComment-73784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.