Help with inserting user
Posted: 2020-04-13 04:01
Hi all, I was hoping I could get a piece of advice, I have two databases, 'Fitbook' and 'Fitsocial', now whenever my customer pays for the product, an event is fired to my server and activates the script bellow, as you can see it either inserts a new user or updates existing user in the membershipUsers table, it updates their expiration plan date, so far so good... but I decided to implement moosocial (https://moosocial.com/), but in order to register an user in the moonsocial system I need to insert the user in the 'Fitsocial' database, all the work in the script refers to 'Fitbook' database, so I would have to go about having a new connection with this new db and inserting the user using this API:
http://fitbookapp.net/fitbook/social/ap ... ister-post but I dont quite know how to set that up? can anyone shed some light? Is a simple new insert sql statement or something deeper? Thank you.
http://fitbookapp.net/fitbook/social/ap ... ister-post but I dont quite know how to set that up? can anyone shed some light? Is a simple new insert sql statement or something deeper? Thank you.
Code: Select all
<?php
<?php
$currDir = dirname(__FILE__);
include("{$currDir}/language.php");
include("{$currDir}/defaultLang.php");
include("{$currDir}/lib.php");
include_once("{$currDir}/header.php");
$adminConfig = config('adminConfig');
print_r($_POST);
$name1 = makesafe($_POST["name"]);
$name = strtoupper($name1);
$price = makesafe($_POST["price"]);
$email = makesafe($_POST["email"]);
$statuss = makesafe($_POST["subscription_status"]);
print_r($data);
print($email . ' ' . $statuss);
$date0 = new DateTime();
$date1 = new DateTime();
$date1->modify('+'.'34'.' day');
$date2 = $date1->format('Y-m-d');
$date3 = new DateTime();
$date3->modify('+'.'365'.' day');
$date4 = $date3->format('Y-m-d');
$sql = "SELECT memberID FROM membership_users WHERE email = '{$email}'";
$datos = sqlValue($sql);
if ( $datos == "" ){
$sql2 = "SELECT custom1 FROM membership_users WHERE custom1 = '{$name}'";
$datos2 = sqlValue($sql2);
if ( $datos2 == "" ){
$sql2cx = "SELECT MAX(flags+1) FROM membership_users ";
$datos2cx = sqlValue($sql2cx);
if($price<20){
sql("INSERT INTO `membership_users` set memberID='{$email}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID='7', isBanned='0', isApproved='1', custom1='{$name}', flags='{$datos2cx}', custom2='1', custom3='', custom4='{$date2}', comments=''", $eo);
}else{
sql("INSERT INTO `membership_users` set memberID='{$email}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID='7', isBanned='0', isApproved='1', custom1='{$name}', flags='{$datos2cx}', custom2='1', custom3='', custom4='{$date4}', comments=''", $eo);
}
}else{
$h1 = rand(1000,100000);
$name2 = $name.$h1;
$sql2x = "SELECT custom1 FROM membership_users WHERE custom1 = '{$name2}'";
$datos2x = sqlValue($sql2x);
if ( $datos2x == "" ){
$sql2cx = "SELECT MAX(flags+1) FROM membership_users ";
$datos2cx = sqlValue($sql2cx);
if($price<20){
sql("INSERT INTO `membership_users` set memberID='{$email}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID='7', isBanned='0', isApproved='1', custom1='{$name2}', flags='{$datos2cx}', custom2='1', custom3='', custom4='{$date2}', comments=''", $eo);
}else{
sql("INSERT INTO `membership_users` set memberID='{$email}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID='7', isBanned='0', isApproved='1', custom1='{$name2}', flags='{$datos2cx}', custom2='1', custom3='', custom4='{$date4}', comments=''", $eo);
}
}else{
$h2 = rand(1000,100000);
$name3 = $name2.$h2;
$sql2cx = "SELECT MAX(flags+1) FROM membership_users ";
$datos2cx = sqlValue($sql2cx);
if($price<20){
sql("INSERT INTO `membership_users` set memberID='{$email}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID='7', isBanned='0', isApproved='1', custom1='{$name3}', flags='{$datos2cx}', custom2='1', custom3='', custom4='{$date2}', comments=''", $eo);
}else{
sql("INSERT INTO `membership_users` set memberID='{$email}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID='7', isBanned='0', isApproved='1', custom1='{$name3}', flags='{$datos2cx}', custom2='1', custom3='', custom4='{$date4}', comments=''", $eo);
}
}
}
$to = $email;
$subject = $name." - Bem Vindo ao Fitbook";
$message = "
<html>
<head>
<title>Bem vindo ao Fitbook!</title>
</head>
<body>
<div style='text-align: center'><img style='width: 250px' src='https://fitbookapp.net/fitbook/logon.png?c=9' /></div>
<table align='center'>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n"."
<tr>
<td align='center'> Olá ".$name.", bem vindo ao Fitbook App!</td>
</tr>
<p><br/></p>". "\n" . "
<tr>
<td align='center'> Seguem abaixo suas credenciais de acesso: </td>
</tr>
</table>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
<table align='center'>
<tr>
<th align='center'>Usuário</th>
</tr>
<tr>
<td align='center'>".$email."</td>
</tr>
<p> </p>
</table>
<table align='center'>
<tr>
<th align='center'>Senha</th>
</tr>
<tr>
<td align='center'>fitbook</td>
</tr>
</table>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
<table align='center'>
<tr>
<th align='center'>Acessar App</th>
</tr>
<tr>
<td align='center'>https://fitbookapp.net/fitbook/</td>
</tr>
<p> </p>
</table>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
<table align='center'>
<tr>
<th align='center'>Contato</th>
</tr>
<tr>
<td align='center'>[email protected]</td>
</tr>
</table>
<p> </p>
<div style='text-align: center'><img style='width: 25px' src='https://fitbookapp.net/fitbook/favicon.png?c=9' /></div>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <[email protected]>' . "\r\n";
mail($to,$subject,$message,$headers);
}else{
$sqldd = "SELECT groupID FROM membership_users WHERE email = '{$email}'";
$datosdd = sqlValue($sqldd);
if($datosdd == "7"){
if($price<20){
sql("UPDATE `membership_users` SET `groupID` = '7', `custom4` = '{$date2}' WHERE email = '{$email}'", $eo);
}else{
sql("UPDATE `membership_users` SET `groupID` = '7', `custom4` = '{$date4}' WHERE email = '{$email}'", $eo);
}
}else{
if($price<20){
sql("UPDATE `membership_users` SET `groupID` = '7', `custom4` = '{$date2}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "' WHERE email = '{$email}'", $eo);
}else{
sql("UPDATE `membership_users` SET `groupID` = '7', `custom4` = '{$date4}', passMD5='" . password_hash('fitbook', PASSWORD_DEFAULT) . "' WHERE email = '{$email}'", $eo);
}
$to = $email;
$subject = $name." - Bem Vindo ao Fitbook";
$message = "
<html>
<head>
<title>Bem vindo ao Fitbook!</title>
</head>
<body>
<div style='text-align: center'><img style='width: 250px' src='https://fitbookapp.net/fitbook/logon.png?c=9' /></div>
<table align='center'>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n"."
<tr>
<td align='center'> Olá ".$name.", bem vindo ao Fitbook App!</td>
</tr>
<p><br/></p>". "\n" . "
<tr>
<td align='center'> Seguem abaixo suas credenciais de acesso: </td>
</tr>
</table>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
<table align='center'>
<tr>
<th align='center'>Usuário</th>
</tr>
<tr>
<td align='center'>".$email."</td>
</tr>
<p> </p>
</table>
<table align='center'>
<tr>
<th align='center'>Senha</th>
</tr>
<tr>
<td align='center'>fitbook</td>
</tr>
</table>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
<table align='center'>
<tr>
<th align='center'>Acessar App</th>
</tr>
<tr>
<td align='center'>https://fitbookapp.net/fitbook/</td>
</tr>
<p> </p>
</table>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
<table align='center'>
<tr>
<th align='center'>Contato</th>
</tr>
<tr>
<td align='center'>[email protected]</td>
</tr>
</table>
<p> </p>
<div style='text-align: center'><img style='width: 25px' src='https://fitbookapp.net/fitbook/favicon.png?c=9' /></div>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <[email protected]>' . "\r\n";
mail($to,$subject,$message,$headers);
}
}
?>