1

i have an enquiry form and submitting the form using jquery/ajax method.

$.ajax({
          url:enquiry.php

I am able to insert records into database table using php mysql_query. When i use db_query in "enquiry.php" page, i am getting errors.

   Call to undefined function db_query()

i want to know how to use db_query to insert records in database table.

  • 2
    You need to bootstrap Drupal before including its APIs, but may I suggest using a menu hook instead of enquiry.php, then you dont have to worry about bootstrapping drupal. – GoodSp33d Mar 13 '13 at 8:01
  • yes, please help me using menu hook – uma Mar 13 '13 at 8:37
2

For that function to be available from outside Drupal, you need to first bootstrap Drupal. This means that, with Drupal 7, the first lines of enquiry.php needs to be the following ones.

define('DRUPAL_ROOT', getcwd());

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

I assume the enquiry.php file is in the same directory containing the index.php file that comes with Drupal.

I would rather suggest you to read the following questions, though:

0

This function is defined in includes/database.inc file.

You have to include database.inc in your file to get db_query() working.

<?php include(“includes/database.inc”); ?>

However if you are trying to access drupal database from a enquiry.php file then all you need to do is to include following lines at the top of your file.

require_once ‘./includes/bootstrap.inc’;
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

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.