Jump to content

[SOLVED] Still having same problem. I really need help please


ccrevcypsys

Recommended Posts

Ok. This is the php code for my upload music page for my site. It works for uploading music just fine but what it has a problem with is it keeps creating a new line in my database with no information on it.

Can you guys please please please help me. I have had this problem for like a week. Thank you.

Heres the appache database table after i open the music upload page.

wtf2.gif

<?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)");

		}

}
			// update category count
	if($_POST['oldCatId']!==$_POST['cat_id']){

			// set old category -1 IF IT WAS IN THERE BEFORE
			$numOldCat = $db->numrows("SELECT * FROM ".$glob['dbprefix']."CubeCart_cats_idx WHERE cat_id = ".$db->mySQLSafe($_POST['oldCatId'])." AND productId = ".$db->mySQLSafe($_POST['productId']));

			if($numOldCat>0){
				$db->categoryNos($_POST['oldCatId'], "-");
			}

			// set new category +1 IF IT WAS NOT IN THERE BEFORE
			$numNewCat = $db->numrows("SELECT * FROM ".$glob['dbprefix']."CubeCart_cats_idx WHERE cat_id = ".$db->mySQLSafe($_POST['cat_id'])." AND productId = ".$db->mySQLSafe($_POST['productId']));

			if($numNewCat == 0) {
				$db->categoryNos($_POST['cat_id'], "+");
			}


			// delete old idx
			$where = "productId = ".$db->mySQLSafe($_POST['productId'])." AND cat_id = ".$db->mySQLSafe($_POST['oldCatId']);  
			$deleteIdx = $db->delete($glob['dbprefix']."CubeCart_cats_idx", $where);
			unset($record);

			// delete new index if it was added as an extra before
			$where = "productId = ".$db->mySQLSafe($_POST['productId'])." AND cat_id = ".$db->mySQLSafe($_POST['cat_id']);  
			$deleteIdx = $db->delete($glob['dbprefix']."CubeCart_cats_idx", $where);
			unset($record);

			// add new idx
			$record['productId'] = $db->mySQLSafe($_POST['productId']);
			$record['cat_id'] = $db->mySQLSafe($_POST['cat_id']);  
			$insertIdx = $db->insert($glob['dbprefix']."CubeCart_cats_idx", $record);
			unset($record);

	}

	if($update == TRUE){
		$msg = "<p class='infoText'>'".$_POST['name']."' ".$lang['admin']['products']['update_successful']."</p>";
	} else {
		$msg = "<p class='warnText'>".$lang['admin']['products']['update_fail']."</p>";
	}

} 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>";
	}
}
if(isset($results[0]['cat_id']))
$music_upload->assign("CAT_ID",$results[0]['cat_id']);
if(isset($results[0]['productId'])) 
$music_upload->assign("PROD_ID",$results[0]['productId']);
$music_upload->assign("VAL_ACTION","cart.php?act=musicUpload");
$music_upload->parse("musicUpload");
$page_content = $music_upload->text("musicUpload");
?>

Link to comment
Share on other sites

I'm not going to take the time to look through all that code.  The first step you should take is modify your database object.  Change your database functions ($db->select, etc.) so that they echo the entire query just before it's executed and echo the return value as well.

 

If the script is inserting the proper records but producing a blank as well, then it is likely you have an error in your MySQL statements.

 

The other possibility that comes to mind is your PHP script redirecting to the insert page using:

header("Location: the/url");

exit();

 

In which case your $_POST values would be empty and might also cause a blank row to be inserted.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.