Forumlar / Cotonti / Development / How to safe data from custom field in a user profile to the DB?

foxhound
#41237 2015-12-14 18:43

I am trying to create a new plugin which adds additional fields to a user profile.

I have gotten it so far that when I edit the user profile the fields are there and actually contain the data I insert to the DB upon plugin install. But I can for the life of me not figure out how to set the plugin up so that if the field value is changed it actually saves this new data when the user presses "submit".

I have created a php for the hooks to "do" when the user updates the profile:
Part=users.edit
File=subscriber.user.edit.update.done
Hooks=users.edit.update.done

I have been trying to get this to work since friday evening and I am about to throw myself out of the window.
Is there someone who can tell me what I need to do so that edited field values get saved to the DB?

 

Thanks in advance!


PS: yes I can use extra fields of course, but it would be nice if I can just make this a plugin so no additonal user input is needed when installing the plugin.

Added 4 hours later:

So here is the edit part of the plugin: 

if (!defined('SED_CODE')) { die('Wrong URL.'); }


$userid = sed_import('id','G','INT');

$sub_sql = sed_sql_query("SELECT user_subscr_end_date, user_subscr_date_stamp, user_subscriber_status FROM $db_users WHERE user_id='$userid'");
	if (sed_sql_numrows($sub_sql) > 0) {
		$sub = sed_sql_fetcharray($sub_sql);

		$sub_end = $sub['user_subscr_end_date'];
		$sub_stamp = $sub['user_subscr_date_stamp'];
		$sub_status = $sub['user_subscriber_status'];
		$sub_stamp = strtotime($sub_end);

	}

$t->assign(array(
	"USERS_EDIT_SUBSCRIPDATE" => "<input type=\"text\" class=\"text\" name=\"subscr_end_date\" value=\"".htmlspecialchars($sub['user_subscr_end_date'])."\" size=\"8\" maxlength=\"10\" />",
	"USERS_EDIT_SUBSCRIPSTATUS" => "<input type=\"text\" class=\"text\" name=\"subscriber_status\" value=\"".htmlspecialchars($sub['user_subscriber_status'])."\" size=\"1\" maxlength=\"1\" />"
));

 

And here is the update.done part of the plugin: 

defined('SED_CODE') or die('Wrong URL'); 

$userid = sed_import('id','G','INT');

$sub_sql_u2 = sed_sql_query("UPDATE $db_users SET user_subscr_end_date='".sed_sql_prep($sub_end)."', user_subscr_date_stamp='".sed_sql_prep($sub_stamp)."', user_subscriber_status='".sed_sql_prep($sub_status)."', user_auth='' WHERE user_id=$userid");

Now, I have tried about a few million different sql queries trying to perform the update and everything fails. My DB values are never updated when I change them in the user edit page.
If I change the update.done part of the plugin and (lets say) hardcode the DB values they get updated properly. So, the plugin works....I just can not figure out how to make the plugin update with the correct field values.

Added 8 hours later:

I tried a few dozen other different values for ".sed_sql_prep($sub_end)." to see if that would properly update the DB but all fial.

<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />

Bu konu foxhound tarafından düzenlendi(2015-12-15 08:03, 8 yıllar önce)