CB AutoAction PHP CODE

10 years 1 month ago #243037 by OLYMP-IA
CB AutoAction PHP CODE was created by OLYMP-IA
Hey. I have a problem and i hope you can help me.

CB AutoAction:
Type: Code
Triggers: onAfterUserUpdate,onAfterUpdateUser
User: Auto
Method: PHP (eval)

My Code:
$URL= "http://test.url=";
$encode = "[cb_field1][name][cb_field2]";
$CallURL = $URL.urlencode($encode);

$con=mysqli_connect("localhost","user","pass","db");
mysqli_query($con,"UPDATE jom_comprofiler SET cb_urlencode='$CallURL' WHERE id='[user_id]'");
mysqli_close($con);

Can you see what is wrong?
Can i do this another way?

Please Log in to join the conversation.

10 years 1 month ago - 10 years 1 month ago #243053 by krileon
Replied by krileon on topic CB AutoAction PHP CODE
You don't need to manually open a connection. Use Joomla or CB API to perform database queries. An example using CB API as follows. For Joomla API please review Joomlas documentation.

$query	=	"UPDATE " . $_CB_database->NameQuote( '#__comprofiler' )
	.	"\n SET " . $_CB_database->NameQuote( 'cb_urlencode' ) . " = " . $_CB_database->Quote( $CallURL )
	.	"\n WHERE " . $_CB_database->NameQuote( 'id' ) . " = " . $_CB_database->Quote( '[user_id]' );
$_CB_database->setQuery( $query );
$_CB_database->query();

Your usage also had no escaping, which is a vulnerability. Please review my example carefully for proper usage. Please also keep in mind you're using "eval" usage of the PHP method, which not all hosts have enabled so you may want to try "create_function" usage instead. Be sure debug mode and maximum error reporting are enabled within Joomla global configuration so if your code errors you'll be able to see what happened.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: OLYMP-IA

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.159 seconds

Facebook Twitter LinkedIn