Facebook Credits API PHP - Update user_id in mySql database after purchase - database

I have an app where I want users to be able to buy in-game credits called coins.
I have set my callback url, and can make a purchase, I get an order_id and settled from the callback, but how do I update the users row in my mySql database after they have made the purchace.
Kinda how my mySql DB looks
ID......FBID............Name..........Coins
7.......1000***797....John..............0
After the user has bought 200 coins for 1 credit, I would like to do this
$SQL = "UPDATE tb_users SET Coins = Coins+200 WHERE FBID = '$usernumber'";
$result = mysql_query($SQL);
But how and where am I supposed to do that? Is it in the callback.php file or in the index.php file after "var callback = function(data)".
I can't seem to pass the user_id from the form on the index to callback.php
So how do I do that, and if that is possible, am I supposed to update my database in the callback.php file??

Nevermind found this out. You can get the info about the user via API the normal way and update the DB in callback.php after "settled".

Related

Piwik change event action name

Is there simple way to change event action name by site id in piwik?
Or everything must be done manually in database?
Or transfer one action name to another?
There is a way to delete everything by site id
DELETE FROM piwik_log_visit WHERE idsite = X;
DELETE FROM piwik_log_link_visit_action WHERE idsite = X;
DELETE FROM piwik_log_conversion WHERE idsite = X;
DELETE FROM piwik_log_conversion_item WHERE idsite = X;
As far as I know, this is not possible in the latest version of Piwik. You need to do that manually when using phpmyadmin to connect to your database.
sorry bro

Retrieving Oracle Password_Verify_Function

I am an IS auditor and I would like to check how we can retrieve the PASSWORD_VERIFY_FUNCTION assigned to users. I understand the script utlpwdmg.sql can be executed to setup the default password resource limits.
If changes were made using ALTER PROFILE, the script utlpwdmg.sql will not show the latest settings.
Please let me know what SQL commands I can execute to show what is the PASSWORD_VERIFY_FUNCTION stored and used in the system.
You can use this query to see source code of stored proc:
--Source of all password functions.
select *
from dba_source
where owner = 'SYS'
and name in
(
--The name of all password functions in use.
--See DBA_USERS.PROFILE to determine which user is using which profile.
select limit
from dba_profiles
where resource_name = 'PASSWORD_VERIFY_FUNCTION'
--Yes, this is intentionally the string 'NULL', that's what Oracle uses here.
and limit <> 'NULL'
)
order by name, line;
To find out what users are using PASSWORD_VERIFY_FUNCTION, you need to find out which profiles are using the function and then see which users are assigned that profile.
select profile from dba_profiles where limit = 'PASSWORD_VERIFY_FUNCTION';
select username from dba_users where profile = ;

Query Drupal User Table for: date created < $today - '100000'

I would like to select users from the Drupal users table where the date created was older than 1 day ago. Then delete those users. This code isn't correct but it will give you an idea of what I am trying to do I just don't know the right DB query.
'
$users = db_select('user', 'created') //I know this is not the right DB query
$count = count($users);
if($count > 0){
$users = user_load_multiple(array_keys($users['user']));
}
$today = getdate();
if ($users < $today - '100000' ) {
user_delete($user->uid)
}
I am thinking about using user_load_multiple() to load the users in to an array to perform the delete action.
Get an array with the uids of the users you want to delete and use user_delete_multiple($arrayOfUidToDelete) : https://api.drupal.org/api/drupal/modules!user!user.module/function/user_delete_multiple/7
Using the function user_load_multiple() can be heavy on ressources if you have a lot of users and you will end with PHP errors (out of memory...).
Plus you don't need to load the users, you just want to delete them.
For the query I will go with db_query instead of db_select if there is no parameters valued by an user (better performances).
So it will look something like :
//get the list of uid
$user_list = db_query("select uid
from users
where CAST(FROM_UNIXTIME(created) as date) < NOW() - INTERVAL 1 DAY"
)->fetchCol();
// delete the users
user_delete_multiple($user_list);

SQL Server CE database and ADO.Net Entity Framework - data not saving

I have a SQL Server CE database file and I have ADO.NET Entity Framework object named History. I perform the following to get the latest ID:
var historyid = (from id in db.Histories // Get the current highest history Id
select (Int32?)(id.Id)).Max();
HistoryID = Convert.ToInt32(historyid);
if (HistoryID == 0) // No current record exists
{
HistoryID = 1; // Set the starter history Id
}
(Not the best way, but it is just to test).
This works well and returns the correct value (If I manually enter an ID of 1, it returns 1, same with 2 etc..)
The issue is with the following code:
History history = new History();
history.Id = 1;
history.SoftwareInstalled = "test";
db.AddToHistories(history);
db.SaveChanges();
The above works and runs through fine, but the changes are not saved to the database! Why is this?
Here is my db variable: dbDeSluggerEntities db = new dbDeSluggerEntities();
Thanks.
Edit: Here is an update: I noticed when I run the program and debug it, it shows that a history has been created and inserted and also gives an error of the primary key already existing, this happens each time I run the application (over and over). However, when I go to server explorer and right click the db and select 'Show Table Data' it shows no data.. When the program is run again, there is no primary key error or history's showing in the debug!
I was having exactly the same problem. By default the database is copied into your bin folder when you run the app and that is used.
My solution was to go into the properties of the db and set it to never copy and to put a full file path to the database in the connection string in the apps config file.

DisplayName - 'User' + UserId - Best Way to Do This

I want to do something like SO does with DisplayName. When someone does not enter a DisplayName, I want to default this to 'User' + UserId. So the first user who signs up would get User1 - since UserId will be 1, the second User2 - since UserId will be 2, and so on.
The easiest way I can think of doing this is using a trigger, but I don't like triggers. I could save the user, then update the user after the save (basically a trigger, but done in my code). Any other ideas on how I can handle this? Is there a way I can set the default value on the column in the database?
I am using Asp.Net MVC 2, C# 4, EF4, and SQL Server 2008.
Select Coalesce(DisplayName, 'User' + Cast(UserID as varchar)) as UserName
You can set the user name in the stored procedure. if a user name has been passed to stored procedure, simply save it. otherwise, get the primary key id of the last entered user and add 1 to it. format it to whatever you like (e.g. User + newID) and save this as the new user's user name.
You can have a computedColumn
[UserName] AS ('User' + CAST(UserID AS VARCHAR)) PERSISTED
I would be inclined to generate it before saving to the database. No input = make one up.
I also would not have user User1, User2, ... but user+random: user6238945, user9287561, user8934678, etc
If you use 1, 2, 3, 4 etc then you are exposing an internal sequence. If someone gets "user4" then I know other users 1 to 3 exist, as well as number 5. This exposure was used many years by AOL or Compuserve (?) for phishing attacks.

Resources