I have create function with code bellow:
function my_add_new_id ( ) {
global $my_db_connect;
global $my_user;
global $my_wpid;
global $my_wpname;
global $my_wpemail;
global $my_generate_pin;
global $my_generate_pass;
global $my_add_id_message;
global $my_svr_region;
global $GetPass;
$my_user = wp_get_current_user();
$my_wpid = $my_user->ID;
$my_wpname = $my_user->display_name;
$my_wpemail = $my_user->user_email;
$my_generate_pin = my_randomPin();
$my_generate_pass = my_randomPass();
if ( isset( $_POST['my_login'] ) )
{
$options = get_option( 'my_settings' );
$my_svr_region = $options['my_serverregion'];
if ( empty ( $my_svr_region ) ) {
$my_svr_region = 1;
}
$mylogin = $_POST['my_login'];
$mypassold = $_POST['my_password'];
$mypinold = $_POST['my_pin'];
if ( empty ( $mylogin ) || empty ( $mypassold ) || empty ( $mypinold ) ) {
$mytw_add_id_message .= '<div class="my-alert-box myerror"><b>All box must fill</b></div>';
}
elseif ( preg_match ( "/[^0-9a-z]/",$mylogin ) ) {
$my_add_id_message .= '<div class="my-alert-box myerror"><b>Please use a - z and 0 - 9</b></div>';
}
elseif ( preg_match ( "/[^0-9a-z]/",$mypassold ) ) {
$my_add_id_message .= '<div class="my-alert-box myerror"><b>Please use a - z and 0 - 9</b></div>';
}
elseif ( preg_match ( "/[^0-9a-z]/",$mypinold ) ) {
$my_add_id_message .= '<div class="my-alert-box myerror"><b>Please use a - z and 0 - 9</b></div>';
}
elseif ((StrLen($mylogin) < 4) or (StrLen($mylogin) > 10)) {
$my_add_id_message .= '<div class="my-alert-box myerror"><b>Must use 4 character and no more than 10 character</b></div>';
}
elseif ((StrLen($mypassold) < 4) or (StrLen($mypassold) > 10)) {
$my_add_id_message .= '<div class="my-alert-box myerror"><b>Must use 4 character and no more than 10 character</b></div>';
}
elseif ((StrLen($mypinold) < 4) or (StrLen($mypinold) > 4)) {
$my_add_id_message .= '<div class="my-alert-box myerror"><b>Must use 4 character</b></div>';
}
$mypass = $my_generate_pass;
$myname = $my_wpname;
$myemail = $my_wpemail;
$mypin = $my_generate_pin;
$mylogin = StrToLower(Trim($mylogin));
$mypass = StrToLower(Trim($mypass));
$mypassold = StrToLower(Trim($mypassold));
$myname = ucwords(Trim($myname));
$myemail = StrToLower(Trim($myemail));
$mypin = StrToLower(Trim($mypin));
$mypinold = StrToLower(Trim($mypinold));
$garamold = $mylogin.$mypassold;
$garamold = md5($garamold);
$garamold = '0x'.$garamold;
$cPanelOld = $mypassold;
$cPanelOld = md5($cPanelOld);
$garam = $mylogin.$mypass;
$garam = md5($garam);
$garam = '0x'.$garam;
$cPanel = $twpass;
$cPanel = md5($cPanel);
$USER_IP = $_SERVER['REMOTE_ADDR'];
$GetAccountInfo = $my_db_connect->get_results ( $my_db_connect->prepare ( 'SELECT * FROM users WHERE name = %s ;', $mylogin ) );
$GetAccountNum = $my_db_connect->get_var ( $my_db_connect->prepare ( 'SELECT COUNT(*) FROM users WHERE name = %s ;', $mylogin ) );
if ( ( !$GetAccountInfo ) || ( !$GetAccountNum ) || ( !$GetAccountNum == 1 ) ) {
$my_add_id_message .= '<div class="tw-alert-box twerror">FAILED: ID '.$mylogin.' not found</div>';
}
else {
foreach ( $GetAccountInfo as $GetDataUser ) {
$GetLogin = $GetDataUser->name;
$GetPass = $GetDataUser->passwd;
$GetPin = $GetDataUser->qq;
$GetMoney = $GetDataUser->money;
$GetWPID = $GetDataUser->wp_ID;
$GetSvrReg = $GetDataUser->svr_region;
}
$GetSvrPass = $my_db_connect->get_var ( $my_db_connect->prepare ( 'CALL my_acquireuserpasswd ( %s, @ID, @PASS ) ;', $mylogin ) );
$GetPassVarHex = $GetSvrPass;
if ( ( $garamold !== $GetPassVarHex ) || ( $twpinold !== $GetPin ) ) {
$my_add_id_message .= '<div class="my-alert-box myerror"><span>FAILED:</span> Old Password and Old Pin not match</div>';
}
else {
$my_db_connect->query ( $my_db_connect->prepare ( 'CALL my_add_other_id ( %s, '.$garam.', %s, %s, %s, %s, %s, %s, %d, %d ) ; ', $mylogin, $cPanel, $mypass, $my_wpname, $USER_IP, $my_wpemail, $mypin, $my_wpid, $my_svr_region ) );
$my_add_id_message .= '<div class="my-alert-box mysuccess"><span>SUCCESS:</span> New ID has been added to your account! </div>';
}
}
}
else {
$my_add_id_message .= 'Please Fill This Form!';
}
echo $my_add_id_message;
}
and mysql Procedure and function bellow:
MYSQL PROCEDURE: my_acquireuserpasswd
=======================================
BEGIN
DECLARE passwdtemp VARCHAR(64);
START TRANSACTION;
SELECT id, passwd INTO uid1, passwdtemp FROM users WHERE name = name1;
SELECT fn_varbintohexsubstring(1,passwdtemp,1,0) ;
COMMIT;
END
================================================================
PARAMETER: in name1 VARCHAR(64), out uid1 INTEGER, out passwd1 VARCHAR(64)
================================================================
MYSQL PROCEDURE: my_add_other_id
================================================================
BEGIN
START TRANSACTION;
UPDATE users SET passwd = passwd1,
Prompt = Prompt1,
answer = answer1,
truename = truename1,
idnumber = idnumber1,
email = email1,
qq = qq1,
passwd2 = passwd1,
wp_ID = wp_ID1,
svr_region = svr_region1
WHERE name = name1;
COMMIT;
END
================================================================
PARAMETER: in name1 varchar(64), in passwd1 varchar(64), in Prompt1 varchar(64), in answer1 varchar(32), in truename1 varchar(255), in idnumber1 varchar(32), in email1 varchar(255), in qq1 varchar(32), in wp_ID1 bigint(20), in svr_region1 int(2)
================================================================
MYSQL FUNCTION: fn_varbintohexsubstring
================================================================
BEGIN
DECLARE pstrout VARCHAR(4000);
DECLARE i int;
DECLARE firstnibble int;
DECLARE secondnibble int;
DECLARE tempint int;
DECLARE hexstring char( 16);
BEGIN
IF( pbinin IS NOT NULL) THEN
SET i= 0, cbytesin= CASE WHEN( cbytesin> 0) THEN cbytesin ELSE LENGTH( pbinin) END,
pstrout= CASE WHEN( fsetprefix= 1) THEN '0x' ELSE '' END,
hexstring= '0123456789abcdef';
IF((( cbytesin * 2) + 2> 4000) or( startoffset< 1)) THEN
RETURN NULL;
END IF;
WHILE( i< cbytesin) DO
SET tempint= ASCII( substring( pbinin, i + startoffset, 1));
SET firstnibble= TRUNCATE((tempint / 16),0);
SET secondnibble= tempint % 16;
SET pstrout= CONCAT(pstrout ,cast( substring( hexstring,( firstnibble+1), 1) AS CHAR), cast( substring( hexstring,( secondnibble+1), 1) AS CHAR));
SET i= i + 1;
END WHILE;
RETURN pstrout;
END IF;
RETURN NULL;
END;
END
================================================================
PARAMETER: fsetprefix bit,pbinin varbinary(8000),startoffset int,cbytesin int
RETURN TYPE: varchar(4000)
================================================================
every time i execute the function i always got "WordPress database error: [Commands out of sync; you can't run this command now]"
those error always appear when i execute the function on form. it give WordPress database error: [Commands out of sync; you can't run this command now] on CALL my_add_other_id
i have re-check those Procedure, there is nothing wrong with it. but the message always say can't run my_add_other_id
Perhaps someone can help me.
Thank You
Aucun commentaire:
Enregistrer un commentaire