I'm creating a wordpress business to let user register into your website. I know that wp-config.php file is used to connect to the db. But in my themes folder do I need to connect to the database again as in the code below.
connect.php
mysql_connect('localhost','xxxxx','xxxxxx');
mysql_select_db('xxxxxx');
init.php
require 'connect.php';
registration.php
include 'init.php';
I have used $connect_error = "Database error!"; in my connect.php file and key in a a wrong host and username, but it doesn't prompt me with error message. I think it doesn't connected to my database.
It is possible to connect to wordpress database from your own theme
so that whenever user will visit site they can see form which can be validate
Process is as follows :
1.To let user register into website there is need to create form on frontend
2.Create your own theme http://www.siteground.com/tutorials/wordpress/wordpress_create_theme.htm
3.Add Subscribe table to your user database with columns as name, username, password, email_id
4.In index.php file add following code to that file to connect database
$myrows = $wpdb->get_results( "INSERT INTO Subscribe(name, username, password, email_id)VALUES('$name', '$uname', '$pswd', '$email')" );
The $wpdb object is not limited to the default tables created by WordPress.
It can be used to read data from any table in the WordPress database such as custom plugin table
Related
How to access (read) custom fields from the directoy?
If I create the Directory Model the custom field of the directory are not shown.
Has someone done this before with App Maker?
Best regards
Karl
Directory Model is read only. You can try to create Calculated Datasource and call AdminDirectory advanced service to get user records with custom fields:
Enable 'Google Admin Directory API'
Click Settings gear button on the top right
Select App Settings tab
Scroll to Advanced Services section
Add 'Google Admin Directory API' service
Create Calculated Model with directory fields you need (let's name it CustomDirectory)
In the calculated model's datasource server script you can add code like this to query user record from the Directory:
var email = query.filters.Email._equals;
var user = AdminDirectory.Users.get(email);
var record = app.models.CustomDirectory.newRecord();
record.Email = email;
record.FieldA = user.FieldA;
record.FieldB = user.FieldB;
...
return [record];
Query calculated datasource from the client:
var ds = app.datasources.CustomDirectory;
ds.query.filters.Email._equals = 'bob#example.com';
ds.load(function() {
console.log(ds.item);
});
You can even avoid writing client side code, if you use bindings magic.
Notes:
Since I'm not Directory admin, I had no chance to test if all links of this chain work.
Most likely you'll need to deploy your app as developer to let all your app access Google Admin Directory API.
Further reading:
https://developers.google.com/apps-script/advanced/admin-sdk-directory
https://developers.google.com/appmaker/security/identity
https://developers.google.com/appmaker/models/calculated
I have a WordPress site called: www.myfirstwp.com.
I want to transfer it's database to new domain which is www.mynewwp.com.
I did it by exporting the DB from www.myfirstwp.com and imported it to www.mynewwp.com
But in this new site ( www.mynewwp.com ) database have all old one database URL.
So, How can I change entire url of old one (www.myfirstwp.com) database in new one ( www.mynewwp.com ) database? Is there any way to do this?
Thank You.
Update Question :
I have an issue in WordPress. When I try to importing XML file with Attachments it's showing me following error message :
Error Message :
Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator and inform them of the time the error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log. Apache Server at mysite.com Port 80
what should I do to solve this type of error message as I am a new user in WordPress.
Thank You.
NOTE: before you tinker with your database be sure to grab a backup first. You do not want to mess up a production database.
The simple way is to open the database on your new domain, open {$prefix}_options and change the home and siteurl rows to reflect the new domain.
This approach works and allows you to operate the site at minimum. The other problems include:
Embedded media links which use the old domain
Other post meta fields and option fields that may contain the old domain.
What I do when this happens is to use raw SQL inside phpMyAdmin (or similar) to search and replace. The following queries take care of post meta and options (95% of the time):
UPDATE wp_options SET option_value = REPLACE(option_value, 'olddomain.com', 'newdomain.com');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'olddomain.com', 'newdomain.com');
The following tables and columns usually have contained domain references in WP:
wp_options.option_value
wp_postmeta.meta_value
wp_posts.post_content
wp_posts.guid
But there might be more places where the domain has been inserted.
I am using built in Drupal 7 user module, fore user registration, forgot-your-password-emails and all that stuff.
I have forgotten my admin password. I have access to my website which is hosted on 1and1.com and also have access to mysql?
Is it possible to change password or email address through SQL so that I can access the admin page?
If it possible how? Can you somebody help me with this?
Thanks!
If you have Drush installed, you just have to enter the following command in the terminal from anywhere inside the site root.
drush upwd admin --password=mynewpassword
Here, admin is the user name; who's password will be changed to mynewpassword.
After several research I tried the following code stored it as a php file in the root directory
saved it as password-reset-admin.php
<?php
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once DRUPAL_ROOT . '/includes/password.inc';
if (isset($_GET['pass']) && !empty($_GET['pass'])) {
$newhash = user_hash_password($_GET['pass']);
}
else {
die('Retry with ?pass=PASSWORD set in the URL');
}
$updatepass = db_update('users')
->fields(array(
'pass' => $newhash,
// 'name' => 'admin',
// 'mail' => 'yourmail#domain.com';
))
->condition('uid', '1', '=')
->execute();
print "Done. Please delete this file immediately!";
drupal_exit();
?>
And after that access the php file through the following:
https://yoursite.com/password-reset-admin.php?pass=newpassword
It just worked..:) Hope it helps others.
Please make sure you delete the file.
To change the password, you need to have shell access to your website. If not, download a copy of drupal 7 on your local machine.
Then, open your terminal and navigate to your Drupal 7 root folder. Then type the following command:
./scripts/password-hash.sh NEW_PASSWORD
Replace NEW_PASSWORD with the new password you need.
This will output a new password hash, copy this password and go to your database manager (phpMyAdmin or similar) and change the admin password to newly generated text.
I don't know of other way to do that, because Drupal is not using MD5 anymore and use a hashing algorithm instead.
Change directory to your Drupal's root.
Then generate the new hash.
In case of Drupal 7:
$ php scripts/password-hash.sh 'your-new-pass-here'
Then execute SQL query to update the administrator's password:
UPDATE users_field_data SET pass='$S$Do7UQjqtEELNccdi92eCXcVJ2KnwUeHrSbK3YhFm8oR3lRJQbMB2' WHERE uid = 1;
In case of Drupal 8 path to script will be:
$ php core/scripts/password-hash.sh 'your-new-pass-here'
Update DB:
UPDATE users_field_data SET pass='$S$Do7UQjqtEELNccdi92eCXcVJ2KnwUeHrSbK3YhFm8oR3lRJQbMB2' WHERE uid = 1;
Clean the cache:
DELETE FROM cache_entity WHERE cid = 'values:user:1';
If you have access to database, then...
Go to the users table in your database and change the admin's email to an email that you have access to.
Afterward, head over to yoursite.com/user/password and enter the email that just changed.
Go to your email and click on the reset link to go into your site and reset your password.
Done!
Tested and it works!
With the access to the table "users" in your Database via PhpMyAdmin for example (i.e. this table can have a prefix that you have already mentionned during the Drupal installation part, so yourPrefix_ can be your project's name as mywebsitename_, and in this case you'll have mywebsitename_users).
You should alter the "pass" column associated with the "uid" column with the value 1 (i.e 1 for the admin user account).
As the encrypted value for the password: Admin_12345 is =>
$S$DifCVXg9tNtHadziyyQJQVLAaZzW5EgS6OjR56D.mk8MpNQs1II2
You can accede to your admin account after replacing the old hashed password value stored in your database that you have totally forgotten.
Don't forget to change the password: Admin_12345 after you accede to your account with an other one.
You can generate query here and run the query in database.
I am using drupal 7.27 version in which I need to connect to moodle site and its database. So I used drupal module moodle_connection to connect it withmoodle site. As it does not offer any end feature functionality. I installed another module called moodle_views but unfortunately there is no data received from the moodle. When I debug I found that connection does not establish between both the sites.
I am calling moodle_connector_connect() function in custom module to connect to Moodle. But no success. And in the moodle connector settings I put the following information:
Database Type : mysql
Database Server : localhost
Database TCP Port : 3306
Database Name : drupal_moodle ('Name of the moodle database')
Database Prefix : mdl_
Database User : root
Database Password : (I don't have password for my database user so I kept blank)
Moodle URL : drupal_moodle (Moodle site url)
Please help me to get out of this.
Regards
Neha
Reading over the bug reports in the Drupal module moodle_connector, I noticed some issues related to setting values for the moodle database connection variables, and some issues with handling error conditions.
Combine this with your mention of blank password, suggests the following line might be a problem.
Reading moodle_connector.module, around line 51 I notice some lazy checking for unset parameters.
// Return false if settings are incomplete.
if (!$type || !$server || !$port || !$username || !$password || !$database) {
return FALSE;
}
It looks like the check for !$password will cause the function moodle_connector_connect() to exit and not connect to the moodle database if any of the values are unset or empty.
As a workaround, and a step in right direction security-wise, could you create a new MySQL user, specifically grant it the necessary privileges to allow Drupal to read the Moodle DB and set a password.
I would also strongly advise that you read over the MySQL 'post installation' section of the manual which advises setting a password on the root user accounts. Having no root password is convenient during initial installation, but is a security problem. Any ordinary user on the machine, or a nearby machine which can connect to port 3306, could gain full access to the database.
http://dev.mysql.com/doc/refman/5.1/en/postinstallation.html
Could you please advice me how to check user status upon login?
I have added a new field named user_flag in wp_users table to control user status. user_flag has value of active or deactivate.
I want to check this field's value when user logs in.
if value is active, then user can proceed login,
but if value is deactivate, then user can not login, and a message will be displayed to notify user that his account is deactivated and he need to contact admin to re-activate account for him to be able to login.
I looked at wp-login.php file but had no idea where to write code to check above logic, could you please advice me where to check user_flag at login time?
Thank you so much.
Stop trying to modify core code and learn to use the pluggable architecture. Also stop modifying the core database tables. You can store additional fields for users in the usermeta table with add_user_meta and retrieve them with get_user_meta. If you start modifying core code and database tables, you will never be able to upgrade wordpress.
To answer your question, use something like the following in functions.php
add_filter('wp_authenticate_user', function($user) {
if (get_user_meta($user->ID, 'user_flag', true) == 'active') {
return $user;
}
return new WP_Error('Account Not Active...');
}, 10, 2);
See https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_authenticate_user