Article Contents Related Articles Tags
  • No tags found.
Was This Helpful? Last Updated
  • 2012/07/05

Example: Input user details into a custom MySQL Table

Note that you are always connected to the Member Guardian database when using custom actions. For this reason, if the MySQL table that you are going to update is outside of the Member Guardian database, you will need to re-connect to the Member Guardian database at the end of your custom action. Not doing so will cause errors with the program. Information on how to do this has been included below.


First, create the custom action PHP file that will run. Save the file to your local computer as "ca_update_db.php".


// Establish the credentials for the
// MySQL database in which your
// custom table is located.

$my_host	= 'localhost';
$my_username	= 'db_username_here';
$my_password	= 'db_password_here';
$my_database	= 'db_name_here';
$table_name	= 'table_being_updated';

// Connect to the database containing your
// custom MySQL table.

mysql_connect($my_host,$my_username,$my_password) or die("MySQL Connection Error: " . mysql_error());
mysql_select_db($my_database) or die("Could not select MySQL database: " . mysql_error());

// Get the information for the user who
// just triggered the custom action.

include $options['ppsd_sl'] . "/custom/custom_actions/functions.php";
$user_data = get_user($user);

// Now update the table. Note that we will
// be inputting a username, first name, last name
// and e-mail into this table, but you have full
// access to all variables available through
// the user's account and the custom action
// $components variable.

$query = mysql_query("
	INSERT INTO `$table_name` (`username`,`first_name`,`last_name`,`email`)
	VALUES ('" . mysql_real_escape_string($user_data['username']) . "','" . mysql_real_escape_string($user_data['first_name']) . "','" . mysql_real_escape_string($user_data['last_name']) . "','" . mysql_real_escape_string($user_data['email']) . "')
") or die('Could not insert data into table: ' . mysql_error());

// Reconnect to the Member Guardian Database

mysql_connect($mysql_server_host,$mysql_username,$mysql_password) or die("MG MySQL Connection Error: " . mysql_error());
mysql_select_db($mysql_database_name) or die("Could not select MG MySQL database: " . mysql_error());


Create the Custom Action

From your Member Guardian admin control panel, click on "Settings » Add a Custom Action" and input the following settings:

FieldInputted Value
NamePost-Registration Auto-Login
TypePHP Code Inclusion
TriggerSelect the trigger at which point this custom action will run.
File LocationUpload the File
Upload FileSelect the post_reg_auto_login.php file created above
Upload ToN/A
Registration FormIf you only want to run the custom action when a specific registration form is used, select the registration form.
ProductIf you only want to run the custom action when a specific product is purchased, select the product.