Hello Pros,
I have an AUTO INCEMENT ID maker that creates an ID for the info being added.
I also have an IMAGE UPLOADING function incorporated into the INFO ADD FORM. There is a PHP prog that I have ADDING the info into the DB as well as renaming the IMAGE as it gets uploaded.
Right now, the renaming scheme isn't working correctly. It's supposed to RENAME the image to the exact number that the AUTO INCREMENT gets assigned it's ID.
I got help with the ID code, but it doesn't seem to GRAB the assigned ID like it's supposed to.
Check it out:
<?PHP
require_once( "./globals.php" );
$sqlquery = "INSERT INTO Dvds
VALUES( \"$dvdId\", \"$title\", \"$regionId\", \"$studio\", \"$year\", \"$link\" )";
$ID = getnewID();
function getnewID() {
$sql = "SELECT LAST_INSERT_ID()";
$sqlhandler = mysql_query($sql,$sqlconnection);
list ($newid) = mysql_fetch_array($sqlhandler);
mysql_free_result($sqlhandler);
return $newid;
function ImgCheck() {
global $imagefile, $imagefile_name, $img, $err;
if ($imagefile and $imagefile != 'none' and $imagefile != '') {
//split up the filename and see if its an acceptable image type
$imgfilename = basename($imagefile_name);
$tmpjunk = explode('.',$imgfilename);
$n = count($tmpjunk) - 1;
$img['ext'] = strtolower($tmpjunk[$n]);
//set up image details array
$tmpsize = GetImageSize($imagefile);
$img['width'] = $tmpsize[0];
$img['height'] = $tmpsize[1];
if ($img[width] < 1) $img['width'] = '0';
if ($img[height] < 1) $img['height'] = '0';
//is it ok?
if ($img[ext] !='gif' and $img[ext] !='jpg' and $img[ext] !='jpeg') {
$err['imagefile'] = true;
$err['imagefiletype'] = true;
return false;
}
//its ok
else {
return true;
}
}
//no image uploaded
else {
return false;
}
}
function ImgSave($filename,$imagetype) {
global $db, $config, $imagefile;
$imglocation = "$config[path_webfilesroot]/$filename";
if (file_exists($imglocation) and is_file($imglocation)) {
unlink($imglocation);
}
return copy($imagefile,$imglocation);
}
function ImgDelete($filename,$imagetype) {
global $config;
$imglocation = "$config[path_webfilesroot]/$filename";
if (file_exists($imglocation) and is_file($imglocation)) {
unlink($imglocation);
}
}
$config['path_webfilesroot'] = '/home/lightso/public_html/dvd/images';
if (ImgCheck()) {
$filename = $ID.'.'.$img[ext];
$imagetype = 'covers';
ImgSave($filename,$imagetype);
}
$results = mysql_query($sqlquery);
mysql_close();
Can anyone help with this? I know my problem lie right here:
$ID = getnewID();
function getnewID() {
$sql = "SELECT LAST_INSERT_ID()";
$sqlhandler = mysql_query($sql,$sqlconnection);
list ($newid) = mysql_fetch_array($sqlhandler);
mysql_free_result($sqlhandler);
return $newid;
But I can't seem to figure it out! Please help!
Thanks in advance!!!