redgtsviper Posted March 9, 2007 Share Posted March 9, 2007 Ok, I don't know if I am doing this right but and help would be great, I am still very green @ php. below you will find my code. In this page I have established a database connect already. the file uploads perfectly with my new name. My real question is how can I put my new file name in my database form my variable $newName. What would be the proper code to do this? <?php // Generate Random Number srand(time()); $random = (rand()%99999999); // Add Random Number to First of File Name $newName="$random"."_"."$file_name"; // Copy to Fold Append New File Name if($file_name !="") { copy ("$file", "images_upload/$newName") or die ("could not copy file"); } else { die(); } //DISPLAY INPUT/OUTPUT echo"Old File Name is: $file_name<br>"; echo"File Size is: $file_size<br>"; echo"File Type is: $file_type<br>"; echo"Random Number is: $random<br>"; echo"New File Name is: $newName"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/41986-upload-image-make-new-random-filename-add-new-name-in-mysql/ Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 You really should put all code inside the [ code ] [ /code ] tags. One way (I am just creating this in my head since you did not post any SQL what so ever) is this: <?php // mysql connection started mysql_query("UPDATE tabl_name SET filename = '".$newName."' WHERE fileid = '".$fileid."'"); ?> This is assuming you have a fileid in the database to identify the file, if not put your identification field there. Either way that is how you update a field using MySQL. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/41986-upload-image-make-new-random-filename-add-new-name-in-mysql/#findComment-203608 Share on other sites More sharing options...
redgtsviper Posted March 9, 2007 Author Share Posted March 9, 2007 Would I need to use UPDATE or INSERT, since this is a new item and I am not updating Quote Link to comment https://forums.phpfreaks.com/topic/41986-upload-image-make-new-random-filename-add-new-name-in-mysql/#findComment-203619 Share on other sites More sharing options...
per1os Posted March 9, 2007 Share Posted March 9, 2007 If it is a new item, you would use INSERT. Sorry about that from the top post it seemed like you were updating a database field that was already there. --FrosT Quote Link to comment https://forums.phpfreaks.com/topic/41986-upload-image-make-new-random-filename-add-new-name-in-mysql/#findComment-203628 Share on other sites More sharing options...
redgtsviper Posted March 9, 2007 Author Share Posted March 9, 2007 I noticed in you previous message you said something about my SQL code. What should my SQL code be for this Quote Link to comment https://forums.phpfreaks.com/topic/41986-upload-image-make-new-random-filename-add-new-name-in-mysql/#findComment-203691 Share on other sites More sharing options...
redgtsviper Posted March 9, 2007 Author Share Posted March 9, 2007 Here is my SQL code, can you tell me why it is not working <?php require_once('Connections/siteData.php'); ?> <?php mysql_select_db($database_siteData, $siteData); $query_Recordset1 = "SELECT * FROM images"; $Recordset1 = mysql_query($query_Recordset1, $siteData) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); mysql_query("INSERT INTO images VALUES ('$newNmae')"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/41986-upload-image-make-new-random-filename-add-new-name-in-mysql/#findComment-203715 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.