need to change database but need help

Discussion in 'MySQL' started by aedges, Nov 19, 2010.

  1. #1
    I have no knowledge in databases so sorry if this is hard to understand.

    I have a fb script that use's the calls "user" but i need it to call "users"
    Also in users i need it to update "userid" and "points" but it updates "id" and "king_author_points"

    Is there a easy way to modify this as i have seen some scripts just adding a line to the database and one line in the file that calls for the database
    the file that calls for the functions

    <?php
    
    function Filter($txt, $nl2br=0)
    {
    	Connect_Database();
    	if(get_magic_quotes_gpc()==1)
    	{
    		$enable = false;
    	}
    	
    	else
    	{
    		$enable = true;
    	}
    	
    	$string = trim($_REQUEST[$txt]);
    	if($enable)
    	{
    		$return = mysql_real_escape_string($string);
    	}
    	else
    	{
    		$return = $string;
    	}
    	
    	if($nl2br==1)
    	{
    		$return = nl2br($string);
    	}
    	return $return; }
    
    
    
    function increaseEnergyForInvitation($id)
    {
    	$user = GetUserDataFromDB($id);
    	$level = $user["level"]+1; 
    	db_execute("Update user set level = '".$level."' where id = ".$id);
    
    }
    function increaseSteminaForInvitations($id,$total)
    {
    	$user = GetUserDataFromDB($id);
    	
    	$stemina = $user["stemina"] +  $total ;
    	db_execute("Update user set stemina = '".$stemina."' where id = ".$id);
    
    }
    function increaseEnergyandSteminaForInvitations($id,$total)
    {
    	$user = GetUserDataFromDB($id);
    	$energy = $user["energy"] + $total ;
    	
    	db_execute("Update user set energy = '".$energy."' where id = ".$id);
    }
    
    //Application Setting
    function ApplicationSetting()
    {
    	return mysql_fetch_assoc(db_execute_return("Select * from setting where id = 1;"));
    }
    //Check User Exist In Database
    function UserExistInDatabase($id)
    {
    	return db_execute_count("Select id from user where id = ".$id);
    }
    //Check group exist for user in database
    function GroupExistForUser($user_id)
    {
    	return db_execute_count("Select id from user where id = ".$user_id." and group_id != 0 and social_circle_name != ''");
    }
    
    ////////////////////////////////////////////////////////////////////////////////REWARD SYSTEM////////////////////////////////////////////////////
    function AddRewardInDatabase($user_id, $points)
    {
    	db_execute("Update user set king_author_points = king_author_points+".$points." where id = ".$user_id." Limit 1;");
    	db_execute("INSERT INTO `offer` (`id` ,`user_id` ,`points_earn` ,`cash_earn` ,`datetime`)VALUES (NULL , '".$user_id."', '".$points."', '".($points/10)."', '".date("Y-m-d H:i:s")."');");
    }
    //Offer cash for user
    function OfferCashForUser($cash)
    {
    	global $user,$user_id, $appSetting;
    	db_execute("Update user set balance = balance + ".$cash.", king_author_points = king_author_points - ".$appSetting["offer_point_for_cash"]." where id = ".$user_id." Limit 1;");
    }
    //Offer Heal for user
    function OfferHealForUser($option)
    {
    	global $user,$user_id, $appSetting;
    	if($option=="Energy")
    	{
    		db_execute("Update user set energy = energy_max, king_author_points = king_author_points - ".$appSetting["offer_point_for_heal"]." where id = ".$user_id." Limit 1;");
    	}
    	elseif($option=="Stemina")
    	{
    		db_execute("Update user set stemina = stemina_max, king_author_points = king_author_points - ".$appSetting["offer_point_for_heal"]." where id = ".$user_id." Limit 1;");
    	}
    	elseif($option=="Health")
    	{
    		db_execute("Update user set health = health_max, king_author_points = king_author_points - ".$appSetting["offer_point_for_heal"]." where id = ".$user_id." Limit 1;");
    	}
    	elseif($option=="Level Up")
    	{
    	$level = $user["level"]+1;
    	//$points = $user["king_author_points"] - $appsetting["offer_point_for_level_up"];
    	db_execute("Update user set level = $level, king_author_points = king_author_points - ".$appSetting["offer_point_for_level_up"]." where id = ".$user_id." Limit 1;");
    	}	
    }
    
    function OfferHealLevelForUser($option)
    {
    global $user,$user_id, $appSetting;
    
    	if($option=="Energy")
    	{
    		$energy = $user["energy_max"] + 1 ;
    		db_execute("Update user set energy_max = $energy, king_author_points = king_author_points - ".$appSetting["offer_point_for_energy_up"]." where id = ".$user_id." Limit 1;");
    	}
    	elseif($option=="Stemina")
    	{
    		
    		$stemina = $user["stemina_max"] + 1 ;
    		db_execute("Update user set stemina_max = $stemina, king_author_points = king_author_points - ".$appSetting["offer_point_for_endurance_up"]." where id = ".$user_id." Limit 1;");
    	}
    	elseif($option=="Health")
    	{
    		
    		$health = $user["health_max"] + 10 ;	
    		db_execute("Update user set health_max = $health, king_author_points = king_author_points - ".$appSetting["offer_point_for_health_up"]." where id = ".$user_id." Limit 1;");
    	}
    }
    
    //Offer Member for user
    function OfferMemberForUser()
    {
    	global $user_id, $appSetting;
    	db_execute("Update user set friend_count = friend_count+1, king_author_points = king_author_points - ".$appSetting["offer_point_for_member"]." where id = ".$user_id." Limit 1;");
    	db_execute("INSERT INTO `friends` (`id` ,`fid1` ,`fid2` ,`status`)VALUES (NULL , '".$user_id."', '0', '1');");
    }
    
    
    ?>
    Code (markup):


    Basicly database name is cpaneluser_fb it updates user "id" + "king_author_points"
    [i need cpaneluser_fb it updates users "COLOR="red"]userid[/COLOR]" + "COLOR="red"]points[/COLOR]" [/COLOR]

    Hope this makes scence to anyone with knowledge.

    Also not that all other databse tables remain the same i have only changed the three in red above
    .

    many thanks


    ------------------

    Edit...

    NVM played with it a bit and got this to work :) Feels good when you work things out yourself ..

    just need to add security @@


     
    Last edited: Nov 19, 2010
    aedges, Nov 19, 2010 IP