Click here to Skip to main content
16,018,797 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<?php
mysql_connect('localhost','ajay_wp','youmint');
mysql_select_db('ajay_wp');

	class Addcoupons {

		function Addcoupons(){
		
			function get_cat_ID($catname=''){

			$catsql="SELECT * FROM `wp_terms` where `name`='".addslashes($catname)."'";
			$allcategory=mysql_query($catsql);
			$allcategories=mysql_fetch_array($allcategory);
			$cateid=$allcategories['term_id'];

		if(!empty($cateid)){
			return $cateid;
			}
				else
			{
			$cateid=0;
			return $cateid;
			}

			
		}
              function get_store_ID( $storename ) {
	        $store = get_term_by( 'name', $storename, 'store' );
	        if ( $store ){
                return $store->term_id;
			}else
	{
	        return 0;
	}
	}                

		function wp_insert_category($catname='')
		{
		$slag=str_replace("'","",htmlentities($catname));
		$slag=strtolower(str_replace(",","",$slag));
		$slag=strtolower(str_replace(" ","_",$slag));
		$catname=addslashes(ucwords($catname));
		
		if(!empty($catname)){
		$term_insert=mysql_query("insert into `wp_terms` set `name`='$catname',`slug`='$slag',`term_group`=0");
		$catid= mysql_insert_id();
		$term_taxonomy=mysql_query("insert into `wp_term_taxonomy` set `term_id`='$catid',`taxonomy`='category',`description`='$catname',`parent`=0,`count`=1");
		$taxonomyid= mysql_insert_id();
		return $taxonomyid;
		}
		}

		function wp_insert_store($storename='',$description='')
		{
			$slag=str_replace("'","",htmlentities($storename));
			$slag=strtolower(str_replace(" ","_",$slag));
	                $slag=strtolower(str_replace(".","_",$slag));
			$storename=addslashes(ucwords($storename));
			//$slag=$slag.".com";
			if(!empty($storename)){
				$term_insert=mysql_query("insert into `wp_terms` set `name`='$storename',`slug`='$slag',`term_group`=0");
				$storeid= mysql_insert_id();
				$term_taxonomy=mysql_query("insert into `wp_term_taxonomy` set `term_id`='$storeid',`taxonomy`='store',`description`='$description',`parent`=0,`count`=1");
				$taxonomyid= mysql_insert_id();
				return $taxonomyid;
			}
		}
		
		function remove_specila_char($catname)
		{
			$slag=str_replace("'","",$catname);
		$slag=str_replace(" ","_",$catname);
		return $slag;
		}

		}
		

		  function TaxonomyIdArray($categories='')
		{
			
			$categoryArray=array_filter(explode("-",$categories));
			$categoryIdArray=array();
			foreach($categoryArray as $catname)
			{
				$catname=trim(stripslashes($catname));
				$my_cat_id1 = get_cat_ID($catname); 
			if($my_cat_id1==0){
					$categoryId=wp_insert_category($catname);
					array_push($categoryIdArray,$categoryId);
					}
					else
						{
					$categoryId=$my_cat_id1;
					$taxodetails=mysql_fetch_array(mysql_query("SELECT * FROM `wp_term_taxonomy`
WHERE `term_id` =$categoryId"));
					$taxonomyid=$taxodetails['term_taxonomy_id'];
					mysql_query("update `wp_term_taxonomy` set `count`=`count`+1 where `term_taxonomy_id`=$taxonomyid");
					array_push($categoryIdArray,$taxonomyid);
						}
			}
			
			return $categoryIdArray;
		}

		  function TaxonomyIdStoreArray($stores='',$description='')
		{
			
			//$storeArray=array_filter(explode("-",$stores));
			$storeIdArray=array();
			//foreach($storeArray as $storename)
			//{
				$storename=trim(stripslashes($stores));
				$my_store_id1 = get_cat_ID($storename); 
			if($my_store_id1==0){
					$storeId=wp_insert_store($storename,$description);
					array_push($storeIdArray,$storeId);
					}
					else
						{
					$storeId=$my_store_id1;
					$taxodetails=mysql_fetch_array(mysql_query("SELECT * FROM `wp_term_taxonomy`
WHERE `term_id` =$storeId"));
					$taxonomyid=$taxodetails['term_taxonomy_id'];
					mysql_query("update `wp_term_taxonomy` set `count`=`count`+1, `description`='$description'  where `term_taxonomy_id`=$taxonomyid");
					array_push($storeIdArray,$taxonomyid);
						}
			//}
			
			return $storeIdArray;
		}
	       
function InsertCoupons($category='',$store='',$offerid='',$title='',$offertype='',$description='',$merchanturl='',$imagesrc='',$code='',$startdate='',$enddate='')	
		{

		$allmetakey=mysql_query("SELECT * FROM `wp_postmeta` WHERE `meta_key` = 'ID' AND `meta_value` = '$offerid'");
			 
			if(mysql_num_rows($allmetakey)==0)
			{
				$postName=str_replace("'","",htmlentities($title));
				$postName=str_replace(".","",htmlentities($postName));
				$postName=str_replace(",","",htmlentities($postName));
				$postName=str_replace("%","",htmlentities($postName));
				$postName=strtolower(str_replace(" ","_",htmlentities($postName)));

  
  mysql_query("insert into `wp_posts` set `post_title`='{$title}', `post_content`='{$description}',`post_excerpt`='{$title}',`post_author`=1,`post_status`='publish',`post_date`=now(),`post_date_gmt`=now(),`post_type`='post',`post_name`='{$postName}'");
   		$id=mysql_insert_id();
		$Url=$merchanturl;
		$Image=$imagesrc;
		$Code=$code;
		foreach(array_filter($category) as $texonomyid)
			{
				mysql_query("insert into `wp_term_relationships` set `object_id`=$id,`term_taxonomy_id`=$texonomyid,`term_order`=0");
			}

			foreach(array_filter($store) as $texonomystoreid)
			{
				mysql_query("insert into `wp_term_relationships` set `object_id`=$id,`term_taxonomy_id`=$texonomystoreid,`term_order`=0");
			}

	  mysql_query("INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES ('{$id}','ID','{$offerid}')");

	  mysql_query("INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES ('{$id}','image','{$Image}')");

	  mysql_query("INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES ('{$id}','type','{$offertype}')");

	  mysql_query("INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES ('{$id}','url','{$Url}')");

	  mysql_query("INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES ('{$id}','code','{$Code}')");
	   mysql_query("INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES ('{$id}','starts','{$startdate}')");
	   mysql_query("INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES ('{$id}','expires','{$enddate}')");
	    mysql_query("INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES ('{$id}','featured','no')");

		return $id;
		
	   
	}
		}

		 function UpdateCoupons($category='',$store='',$offerid='',$title='',$offertype='',$description='',$merchanturl='',$imagesrc='',$code='',$startdate='',$enddate='')	
		{
		$allmetakey=mysql_fetch_array(mysql_query("SELECT `post_id` FROM `wp_postmeta` WHERE `meta_key` = 'ID' AND `meta_value` = '$offerid'"));
		$Postid=$allmetakey['post_id'];
		if($Postid!=0){
			mysql_query("update `wp_postmeta` set `meta_value` ='$imagesrc', WHERE `post_id` = '$Postid' and `meta_key` = 'image'");
			mysql_query("update `wp_postmeta` set `meta_value` ='$offertype', WHERE `post_id` = '$Postid' and `meta_key` = 'type'");
			mysql_query("update `wp_postmeta` set `meta_value` ='$merchanturl', WHERE `post_id` = '$Postid' and `meta_key` = 'url'");
			mysql_query("update `wp_postmeta` set `meta_value` ='$code', WHERE `post_id` = '$Postid' and `meta_key` = 'code'");
			mysql_query("update `wp_postmeta` set `meta_value` ='$startdate', WHERE `post_id` = '$Postid' and `meta_key` = 'starts'");
			mysql_query("update `wp_postmeta` set `meta_value` ='$enddate', WHERE `post_id` = '$Postid' and `meta_key` = 'expires'");
			return $Postid;
		}
		}
		
	}

?>


cannot run the file thru wordpress i guess some function is bad guys please help
Posted
Comments
enhzflep 24-Jun-13 6:32am    
You're not going to get any help with such an inconsiderate 'question'.

"Php function not working" and "cannot run file thru wordpress I guess some function is bad guys please help" are not even close to good enough for the sum total of your question body and title.

1. Break your code down into smaller pieces.
2. Isolate the one that does not function as expected.
3. Articulate the discrepancy between expected and observed behaviour.

I also really suggest that you read the following: www.sscce.org
nkhldhar 24-Jun-13 7:16am    
thanks anyways its done now!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900