Jump to content

[SOLVED] upload music form


ccrevcypsys

Recommended Posts

Well it seems that i fixed the original problem. but now every time the page opens or is refreshed it creates a new row in the database that is blank. heres a screen shot of the db after i had refreshed

wtf2 

<?php
$music_upload=new XTemplate ("skins/".$config['skinDir']."/styleTemplates/content/musicUpload.tpl");
if($ccUserData[0]['customer_id']>0){
$music_upload->assign("TXT_USERNAME",$ccUserData[0]['customer_id']);
}
$query = "SELECT * FROM ".$glob['dbprefix']."CubeCart_inventory INNER JOIN ".$glob['dbprefix']."CubeCart_category on ".$glob['dbprefix']."CubeCart_inventory.cat_id = ".$glob['dbprefix']."CubeCart_category.cat_id ".$whereClause." ORDER BY name ASC";
$results = $db->select($query);
// generate product code
if(empty($_POST['productCode'])){

	$chars = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N",
			"O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3",
			"4","5","6","7","8","9","0");
	$max_chars = count($chars) - 1;
	srand((double)microtime()*1000000);
		for($i = 0; $i < 5; $i++){
			$randChars = ($i == 0) ? $chars[rand(0, $max_chars)] : $randnum . $chars[rand(0, $max_chars)];
		}
	$record["productCode"] = $db->mySQLSafe(strtoupper(substr($_POST['name'],0,3)).$randChars.$_POST['cat_id']);

} else {
	$record["productCode"] = $db->mySQLSafe($_POST['productCode']);	
}

$record["name"] = $db->mySQLSafe($_POST['name']);		
$record["cat_id"] = $db->mySQLSafe($_POST['cat_id']);	
$record["description"] = $db->mySQLSafe($_POST['FCKeditor']);
$record["albumName"] = $db->mySQLSafe($_POST['albumName']);
$record["lPoints"] = $db->mySQLSafe($_POST['lPoints']);
$record["image"] = $db->mySQLSafe($_POST['imageName']);
$record["price"] = $db->mySQLSafe($_POST['price']);  
$record["sale_price"] = $db->mySQLSafe($_POST['sale_price']);
$record["stock_level"] = $db->mySQLSafe($_POST['stock_level']); 
$record["useStockLevel"] = $db->mySQLSafe($_POST['useStockLevel']);
$record["digital"] = $db->mySQLSafe($_POST['digital']);
$record["digitalDir"] = $db->mySQLSafe($_POST['digitalDir']);
$record["prodWeight"] = $db->mySQLSafe($_POST['prodWeight']);
$record["taxType"] = $db->mySQLSafe($_POST['taxType']); 
$record["showFeatured"] = $db->mySQLSafe($_POST['showFeatured']); 
$record["release_date"] = $db->mySQLSafe($_POST['releaseDate']);
        $record["type"] = $db->mySQLSafe($_POST['Type']);
        $record["gender"] = $db->mySQLSafe($_POST['gender']);
$record["customer_id"] = $db->mySQLSafe($_POST['artist']);
// if image is a JPG check thumbnail doesn't exist and if not make one
$imageFormat = strtoupper(ereg_replace(".*\.(.*)$","\\1",$_POST['imageName']));
if($imageFormat == "JPG" || $imageFormat == "JPEG" || $imageFormat == "PNG" || ($imageFormat == "GIF" && $config['gdGifSupport']==1)){

	if(file_exists($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName'])){
		@chmod($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName'], 0775);
		unlink($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName']);
	}

	$thumb=new thumbnail($GLOBALS['rootDir']."/images/uploads/".$_POST['imageName']);
	$thumb->size_auto($config['gdthumbSize']);
	$thumb->jpeg_quality($config['gdquality']);
	$thumb->save($GLOBALS['rootDir']."/images/uploads/thumbs/thumb_".$_POST['imageName']);
}

if(trim($_POST["Type"])!='Song'){
for($i=1;$i<=20;$i++){
	if(is_array($_FILES['digitalDir'.$i])){
		$date_str=date('Ymdhis');
		$songeFormat = strtoupper(ereg_replace(".*\.(.*)$","\\1",$_FILES['digitalDir'.$i]['name']));
		$songSample_format = strtoupper(ereg_replace(".*\.(.*)$","\\1",$_FILES['digitalSample'.$i]['name']));
		if($songeFormat=='MP3'){
			copy($_FILES['digitalDir'.$i]['tmp_name'],"songs/".$date_str."_".str_replace('-','_',str_replace(' ','_',$_FILES['digitalDir'.$i]['name'])));
			$song_files["digitalDir".$i] = $db->mySQLSafe("songs/".$date_str."_".str_replace('-','_',str_replace(' ','_',$_FILES['digitalDir'.$i]['name'])));
			if($_FILES['digitalSample'.$i]['name']!=''){
				copy($_FILES['digitalSample'.$i]['tmp_name'],"songs/samples/".$date_str."_".str_replace('-','_',str_replace(' ','_',$_FILES['digitalSample'.$i]['name'])));
				$song_files["digital_sample".$i] = $db->mySQLSafe("songs/samples/".$date_str."_".str_replace('-','_',str_replace(' ','_',$_FILES['digitalSample'.$i]['name'])));
				$song_files["title".$i] = $db->mySQLSafe($_POST['songtitle'.$i]);
			}
		}
	}
}

}else{
if(is_array($_FILES['digitalDir'])){
	$date_str=date('Ymdhis');
	$songeFormat = strtoupper(ereg_replace(".*\.(.*)$","\\1",$_FILES['digitalDir']['name']));
	$songSample_format = strtoupper(ereg_replace(".*\.(.*)$","\\1",$_FILES['digitalSample']['name']));
	if($songeFormat=='MP3'){
	copy($_FILES['digitalDir']['tmp_name'],"songs/".$date_str."_".str_replace('-','_',str_replace(' ','_',$_FILES['digitalDir']['name'])));
	$record["digitalDir"] = $db->mySQLSafe("songs/".$date_str."_".str_replace('-','_',str_replace(' ','_',$_FILES['digitalDir']['name'])));
	if(is_array($_FILES['digitalSample'])){
		copy($_FILES['digitalSample']['tmp_name'],"songs/samples/".$date_str."_".str_replace('-','_',str_replace(' ','_',$_FILES['digitalSample']['name'])));
                	$record["digital_sample"] = $db->mySQLSafe("songs/samples/".$date_str."_".str_replace('-','_',str_replace(' ','_',$_FILES['digitalSample']['name'])));
	}}
}
}
if(isset($_POST['productId']) && $_POST['productId']>0) {

	$where = "productId=".$db->mySQLSafe($_POST['productId']);
	$update = $db->update($glob['dbprefix']."CubeCart_inventory", $record, $where);
	unset($record, $where);
	//delete old files
	$db->misc ("delete from cc_album_files where albumid=".$_POST['productId']);
	if(trim($_POST['Type'])=='Album'){
		for($i=1;$i<=20;$i++){
			if($song_files['digitalDir'.$i]!='')
			$db->misc("insert into cc_album_files (albumid,path,title) values(".$_POST['productId'].",".$song_files['digitalDir'.$i].",".$song_files['title'.$i].")");
			if($song_files['digital_sample'.$i]!='')
			$db->misc("insert into cc_album_files (albumid,path,title,sample) values(".$_POST['productId'].",".$song_files['digital_sample'.$i].",".$song_files['title'.$i].",1)");

		}

}

} else {

	$insert = $db->insert($glob['dbprefix']."CubeCart_inventory", $record);

	$record['cat_id'] = $db->mySQLSafe($_POST['cat_id']);
	$prodid=$record['productId'] = $db->insertid();  
	////////////////////////////////////////points system/////////////////////////////////////
	$insert = $db->misc("insert into cc_points set songid='".$record['productId']."'");
	if(trim($_POST['Type'])!='Song'){
		for($i=1;$i<=20;$i++){
			if($song_files['digitalDir'.$i]!='')
			$db->misc("insert into cc_album_files (albumid,path,title) values(".$record['productId'].",".$song_files['digitalDir'.$i].",".$song_files['title'.$i].")");
			if($song_files['digital_sample'.$i]!='')
			$db->misc("insert into cc_album_files (albumid,path,title,sample) values(".$record['productId'].",".$song_files['digital_sample'.$i].",".$song_files['title'.$i].",1)");
		}
	}
	unset($record);
	$record['cat_id'] = $db->mySQLSafe($_POST['cat_id']);
                $record['productId'] = $prodid;
	//////////////////////////////////////////////////////////////////////////////////////////
	$insertIdx = $db->insert($glob['dbprefix']."CubeCart_cats_idx", $record);
	unset($record);

	if($insert == TRUE){

		$msg = "<p class='infoText'>'".$_POST['name']."' ".$lang['admin']['products']['add_success']."</p>";

		// notch up amount of products in category
		$db->categoryNos($_POST['cat_id'], "+");

	} else {
		$msg = "<p class='warnText'>".$lang['admin']['products']['add_fail']."</p>";
	}
}

$music_upload->assign("VAL_ACTION","cart.php?act=musicUpload");
$music_upload->parse("musicUpload");
$page_content = $music_upload->text("musicUpload");
?>

Link to comment
https://forums.phpfreaks.com/topic/64320-solved-upload-music-form/
Share on other sites

Have you tried adding a hidden field on your form and check it if was submitted?

 

<input name="is_submitted" type="hidden" value="1">

 

Then just check if it was submitted or not.

 

$submitted = $_POST['is_submitted'];

if ($submitted){
//do your code insert stuff
}

 

That might work...

 

its not that

it gets submited

its the fact that every time the page loads up it adds a blank song to the database before i even hit submit. It happens when the page is rendering

Have you tried adding a hidden field on your form and check it if was submitted?

 

<input name="is_submitted" type="hidden" value="1">

 

Then just check if it was submitted or not.

 

$submitted = $_POST['is_submitted'];

if ($submitted){
//do your code insert stuff
}

 

That might work...

 

I had this problem, this is probably not the best way to do it but...

 

Something like...

<?php
if (isset($_POST['submited'])) {

// Thank you once it IS submitted 
?>
<h1>Thank you for posting...</h1>
blah blah...
<?php
// If it's not submitted I show the form
} else {
?>

<!-- Your Form -->

<?php
}
?>

 

This worked for me.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.