0

I want to create a script file that I can call using a form on submit. For example I can use:

action="action.php?uid=1&method=deleteuser"

This would trigger the script to result in the function deleteuser in file action.php deleting uid 1. However, when I tried to create this file and put it in the home scripts folder it couldn't call basic drupal commands such as db_query. Where and how can I generate such a script file so that I can access drupals core functions?

0

You can make your script file with following statements:

<?php
define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']); // Define the DRUPAL_ROOT constant which is used in many places.
$base_url = 'http://'.$_SERVER['HTTP_HOST']; // Again, this is used in many places.
require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; // Include the boostrap file.
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION); // Start things up to whatever level you need.
//drupal_set_message('custom script');
print db_query("SELECT title FROM {node} WHERE nid = :nid", array(':nid' => 1))->fetchColumn();
?>

But it is not a good practice to handle form submit or whatever.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.