Renaming Image Uploaded and Updating Database

Good day all, please i have been trying to Renaming images uploaded during registration with PHPmaker and updating it using the userid as the new name after update in the database. i’d be glad if anyone in here can help out.
Here is the structure in the Database.
CREATE TABLE IF NOT EXISTS products (
pid int(11) NOT NULL AUTO_INCREMENT,
price decimal(8,2) NOT NULL,
title varchar(128) NOT NULL,
details text NOT NULL,
image varchar(128) NOT NULL,
PRIMARY KEY (pid)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

Hoping to here from any helper soon.

You may use Row_Inserting server event (see the topic Server Events and Client Scripts → Row_Inserting in the help file), e.g.

$rsnew[“image”] = “newname.png”;

Thanks,
Tried to make it work as advised but still coulding get it to work.
Any other suggestion would be appreciated.
Many thanks

That is it. (Note that my previous post was example for the Add page, if you want to do it for the Edit page, use Row_Updating server event, see the topic Server Events and Client Scripts in the help file.) You may post your complete code in your event for discussion.

Thanks, i really appreciate.

A) After several work around i was able to achieve the desired rename during upload thanks to you and several others in the forum. i came on to use the following which actually worked during the process of the upload.

// Row Inserting event
function Row_Inserting($rsold, &$rsnew) {
// Enter your code here
// To cancel, set return value to FALSE
$email = $rsnew[“email”] ;
$prefix = ‘img_’ ;
$ext = ‘.jpg’ ;
$new_image = $prefix.$email.$ext ;
if ($rsnew[“photo”] != “”) {
$rsnew[“photo”] = “$new_image” ;
}
return TRUE;
}

The above code worked perfectly.

  • The second issue is when i try to edit or update the row it doesn’t rename the image again.
  • The third issue is that i cant figure out how to update two or more fields using similar code as above.

B) I decided to use the following code in the Updating functions

// Row Updating event
function Row_Updating($rsold, &$rsnew) {
// Enter your code here
// To cancel, set return value to FALSE
if ($rsnew[“photo”] != “”) { //change from $rsold[“Photo”] to “”
$NewFiles = explode(MULTIPLE_UPLOAD_SEPARATOR, $rsnew[“photo”]);
$FileCount = count($NewFiles);
for ($i = 0; $i < $FileCount; $i++) {
if ($NewFiles[$i] <> “”) {
$file = $NewFiles[$i];
$file_extension = substr(strtolower(strrchr($file, “.”)), 1);
$email = $rsold[“email”];
$file = $email.“-”.($i+1).“.”.$file_extension;
$NewFiles[$i] = $file;
}
}
$FileName = implode(MULTIPLE_UPLOAD_SEPARATOR, $NewFiles);
$rsnew[‘photo’] = $FileName;
}
return TRUE;
}
The above works perfectly but i now need it to work for multiple images.

Thanks once again for your assistance and that of any other great coder in here.
Really appreciate