I have added a field in 'Manage User Fields' & when an email is sent to the administrator notifying them of the new user registration, I want to include this new field.
I have written some code to get this new field from #__vm_user_info in /administrator/components/com_virtuemart/classes/ps_shopper.php, in the _sendMail function, as well as added the variable to $message2.
ASEND_MSG has been modified to accept the parameter, but the field is not included in the email to the admin when a user is created. When I go look in the table, the data is there. So to trouble shoot, I hard coded a user name in the select statement, added another user & the correct value was sent for the hard coded user, not the one just added. I am now thinking that it is a commit issue with MySQL, so I put a sleep(4) in the code before I attempt to get the value...no luck.
Can anyone shine some light on this for me??
LarryR....
administrator/components/com_virtuemart/classses/ps_shopper.php
Need to add with the following code in function add() before "return true" line :
/**************************** ***********************/
$pwd = $_POST['password'];
$db = JFactory::getDBO();
$query = "SELECT id, name, email, username"
. "\n FROM #__users"
. "\n ORDER by id DESC LIMIT 1"
;
$db->setQuery( $query );
$rows = $db->loadObjectList();
$namee = $rows[0]->name;
$emaill = $rows[0]->email;
$usern = $rows[0]->username;
$pwd;
$lid = $rows[0]->id;
$dbv = new ps_DB;
echo $query = "SELECT *"
. "\n FROM #__{vm}_user_info"
. "\n WHERE user_id=$lid"
;
$dbv->setQuery( $query );
$fid = $db->loadObjectList();
$field = $fid[0]->extra_field_1;
$user = clone(JFactory::getUser());
$usersConfig = &JComponentHelper::getParams( 'com_users' );
if ($usersConfig->get('allowUserRegistration') == '0') {
JError::raiseError( 403, JText::_( 'Access Forbidden' ));
return false;
}
// If user activation is turned on, we need to set the activation information
$useractivation = $usersConfig->get( 'useractivation' );
if ($useractivation == '1')
{
jimport('joomla.user.helper');
$user->set('activation', md5( JUserHelper::genRandomPassword()) );
$user->set('block', '1');
}
$component = 'com_user';
$activation_link = $mosConfig_live_site."/index.php?option=$component&task=activate&activation=".$user->get('activation');
$this->_sendMail( $namee , $emaill, $usern, $pwd, $activation_link);
/************************************************** Spinz ********************************************/
Note : Here we created the mail function for username and password to users mail.
administrator/components/com_virtuemart/classses/ps_shopper.php
Need to comment the line in function register_save() before "return true" line:
// Send the registration email
//$this->_sendMail( $name, $email, $username, $password, $activation_link );
Note: Here the mail function generated we need to comment that mail functions and create another mail function in add() function of ps_shopper.php in first point.
administrator/components/com_virtuemart/classses/ps_shopper.php
Need to get the extra added field (extra_field_1) in jos_vm_user_info table in the function _sendmail() with following code and that field sent through the mail to user.
/****************************************************************/
$db = JFactory::getDBO();
$query = "SELECT id, name, email, username"
. "\n FROM #__users"
. "\n ORDER by id DESC LIMIT 1"
;
$db->setQuery( $query );
$rows = $db->loadObjectList();
$lid = $rows[0]->id;
$dbv = new ps_DB;
$query = "SELECT *"
. "\n FROM #__{vm}_user_info"
. "\n WHERE user_id=$lid"
;
$dbv->setQuery( $query );
$fid = $db->loadObjectList();
$field = $fid[0]->extra_field_1;
$subject = sprintf ($VM_LANG->_('SEND_SUB',false), $name, $mosConfig_sitename);
$subject = vmHtmlEntityDecode($subject, ENT_QUOTES);
if ($mosConfig_useractivation=="1"){
$message = sprintf ($VM_LANG->_('USEND_MSG_ACTIVATE',false), $name, $mosConfig_sitename, $activation_link, $mosConfig_live_site, $username, $pwd, $field );
} else {
$message = sprintf ($VM_LANG->_('PHPSHOP_USER_SEND_REGISTRATION_DETAILS',false), $name, $mosConfig_sitename, $mosConfig_live_site, $username, $pwd, $field);
}
/*************************************/
Note :
Initialize the variable "$field" get the extra added field value using query. Then that the extra field value is assigned by message section of the mail.(initialize variable $field having the a value added extra fields in virtuemart).
administrator/components/com_virtuemart/languages/common/english
replace the messages for the following code:
'USEND_MSG_ACTIVATE' => 'Hello %s,
Thank you for registering at %s. Your account is created and must be activated before you can use it.
To activate the account click on the following link or copy-paste it in your browser:
%s
After activation you may login to %s using the following username and password:
Username - %s
Password - %s
Degree - %s'
2.'PHPSHOP_USER_SEND_REGISTRATION_DETAILS' => 'Hello %s,
Thank you for registering at %s. Your customer account has been created.
You may login to %s using the following username and password:
Username - %s
Password - %s
Degree - %s
'
Note:
The extra added values assigned by the string %s in language file.
The message having the string values of extra added field value in virtuemart.
The degree shows the added extra field
Related
I am new to SQL and PHP. My goal is simple: Check if there is already an email adress stored in database. I am using following code:
$email = info#test.pl;
$conn = new mysqli("localhost", "root", "", "mysite"); // Create connection
if ($conn->connect_error) { // Check connection
die("Connection failed: " . $conn->connect_error);
}
$stmt = $conn->prepare("SELECT * FROM contacts WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($email);
$stmt->store_result();
$result = $stmt->num_rows;
echo $result;
Every time i get an error. It says i am using wrong numbers of parameters in bind_result. How it can be?
If you're new to all this, I would recommend using PDO instead of mysqli.
As for your error: you select * columns but bind only one.
You can change the query to select email, or do away with binding the resultset:
if all you want is to check for the presence of the email, all you need is the rowcount.
I want to check if email already exists in the DB, starting at this and need some help. Here is the code:
<?php
require_once('includes/connects.php');
$username = $_POST['username'];
$nome = $_POST['nome'];
$password = sha1($_POST['password']);
$email = $_POST['email'];
$checkmail = mysql_query("SELECT email FROM utilizadores WHERE email = '$email'");
$result = $conn->query($checkmail);
if($result->num_rows == 0){
$querygo = "INSERT INTO utilizadores (username, nome, password, email) VALUES ('$username', '$nome', '$password', '$email'";
$result = $conn->query($querygo);
header('Location: index.php');
} else {
echo 'DONT WORK';
}
This is the error:
Fatal error: Call to a member function query() on a non-object in
C:\Sites\deca_13L4\deca_13L4_23\MiniProjeto\bussaco\registo.php on
line 12 Warning: Unknown: 1 result set(s) not freed. Use
mysql_free_result to free result sets which were requested using
mysql_query() in Unknown on line 0
Looking at your code, unsure what value this has in the mix of everything since that is exactly where the error occurs:
$result = $conn->query($checkmail);
So I would change your code to be like this:
<?php
require_once('includes/connects.php');
$username = $_POST['username'];
$nome = $_POST['nome'];
$password = sha1($_POST['password']);
$email = $_POST['email'];
$checkmail = mysql_query("SELECT email FROM utilizadores WHERE email = '$email'");
if(!$checkmail){
$querygo = "INSERT INTO utilizadores (username, nome, password, email) VALUES ('$username', '$nome', '$password', '$email'";
$result = $conn->query($querygo);
header('Location: index.php');
} else {
echo 'DONT WORK';
}
But that said, it’s unclear to me where the actual needed mysql_connect comes from. Is that in require_once('includes/connects.php');? I hope so. Otherwise mysql_query won’t work no matter what. To execute a query you need a connection.
just make your code as simple as you can. So here:
<?php
require_once('includes/connects.php');
$username = $_POST['username'];
$nome = $_POST['nome'];
$password = sha1($_POST['password']);
$email = $_POST['email'];
$checkmail = mysql_query("SELECT email FROM utilizadores WHERE email = '$email'");
$num_rows = mysql_num_rows($checkmail);
if($num_rows){
$querygo = "INSERT INTO utilizadores (username, nome, password, email) VALUES ('$username', '$nome', '$password', '$email'";
$result = mysql_query($querygo);
header('Location: index.php');
} else {
echo 'DONT WORK';
}
I am working on a facebook application, and some of the data that I want are the groups of that user and the other members of that group as shown in this code:
$groups = $facebook->api('/me/groups?since=0');
mysqlc();
foreach($groups['data'] as $group){
$gid=GetSQLValueString($group['id'], "text");
$name=GetSQLValueString($group['name'], "text");
//echo $gid." -> ".$name;
$query = sprintf("SELECT * FROM `group` WHERE gid = %s", $gid);
$res = mysql_query($query) or die('Query failed: ' . mysql_error() . "<br />\n$sql");
if(mysql_num_rows($res) == 0){
$iquery = sprintf("INSERT INTO `group`(gid, name) values(%s,%s)", $gid, $name);
$ires = mysql_query($iquery) or die('Query failed: ' . mysql_error() . "huhuhu<br />\n$sql");
}
$c = explode("'", $gid);
$params = "/".$c[1]."/members";
echo "'".$params."'";
$members = $facebook->api("'".$params."'");
print_r($members);
}
what I wanted to have after this code are the members of each group that the user has, but this code is not working properly.. So my main query is what is the proper way or replacement to this line:
$members = $facebook->api("'".$params."'");
where I can use the fetched group Id. thanks a lot to those who will answer my query.
I am trying to create a simple fb app that retrieves the name of the user using fql_query.
Code :
require_once 'facebook.php';
$appapikey = 'xxxx';
$appsecret = 'xxxx';
$facebook = new Facebook($appapikey, $appsecret) ;
$user_id = $facebook->require_login();
$q = "SELECT name FROM user WHERE uid='$user_id'";
$name = $facebook->api_client->fql_query($q);
echo "Name : $name[0][name]";
Output:
Name : Array[name]
Can you tell me what's going wrong here?
Thanks!
Mistake is in this line:
echo "Name : $name[0][name]";
you are including $name[0][name] in quotes, this should be
echo "Name : {$name[0][name]}";
or
echo "Name : ".$name[0][name];
An FQL query always returns an array, even if there is only one item in the result. Think of the result as rows in a normal SQL query.
Any time that I use arrays or database/API calls in PHP I print_r($array_name) to see what was returned. So this:
$name = $facebook->api_client->fql_query("SELECT name FROM user WHERE uid=$user_id");
print_r($name);
Should return this:
Array
(
[0] => Array
(
[name] => First Last
)
)
Another thing, I never put tick marks around values/variables in FQL.
$q = "SELECT name FROM user WHERE uid=$user_id";
$name = $facebook->api_client->fql_query($q);
But when you print the value you should put single quotes around the reference to the named index (in this case, 'name') and you should not wrap it all in double quotes:
echo "Name : " . $name[0]['name'];
This is a simple question. I have a little program here that reads
a list of emails in a specific inbox of a user account specified by the program.
I can access an account using its username, password and host. The only problem is I don't know how to get the date on each of these mails.
Here's some part of my code:
my $pop = new Mail::POP3Client(
USER => $user, #some user,password & host assigned
PASSWORD => $pass,
HOST => $host );
for( $i = 1; $i <= $pop->Count(); $i++ ) {
#header = $pop->Head($i);
#body = $pop->Body($i);
$mail = new Mail::MboxParser::Mail(\#header, \#body);
$user_email = $mail->from()->{email
print "Email:".$user_email; #this prints out right
foreach( $pop->Head( $i ) ) {
/^(Date):\s+/i && print $_, "\n";
$date = $_;
}
}
Now what i need is to get the only one date for each email,
but that loop gives me all.. but when remove the loop, it
returns an error. I'm using Perl.
Kindly help me? :)
According to MboxParser::Email doc, you should be able to do:
$date = $mail->header->{'date'}; #Keys are all lowercase
If you have more than one date returned, $date will be an array ref and you can access the first occurence of the Date with:
$date->[0];
So you shouldn't need to loop through the header and use a regular expression.