Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7406467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:33:45+00:00 2026-05-29T05:33:45+00:00

I have build a website in Drupal, and I am trying to create a

  • 0

I have build a website in Drupal, and I am trying to create a fun way to get members involved with the site by building a userpoint system, the system is all in place, but I’m trying to make a shop where they can buy ‘titles’.

This is the script I wrote for the shop, with a bit of error handling, but I’m stuck with a problem,

In my JavaScript, I have the function buyitem( ) with 2 variables, which I want to use in my PHP functions which check everything in my database, is there a way to get those variables from JavaScript to the PHP function I wrote without going to an external PHP file?

<?php
    include "php-scripts/DBConnection.php";
    $con = getconnection();
    mysql_select_db("brokendi_BD", $con);
    
    
    function getKarma()
    {
           $result = mysql_query("SELECT * FROM userpoints WHERE uid='getUID()'");
           $row = mysql_fetch_array($result);
           $currentkarma = (int)$row['points'];
           
          return $currentkarma;
    }
    
    function getUID()
    {
         global $user;
         if ($user->uid) 
         { 
              $userID=$user->uid;
              return $userID;
         }
         else
        {
              header('Location: http://brokendiamond.org/?q=node/40');
        }
    }
    
    function hasRole($roleID)
    {
           $usersid = getUID();
           $returnValue = false;
           $result = mysql_query("SELECT * FROM users_roles");
           while ($row = mysql_fetch_array($result))
          { 
               if ($row['uid'] == $usersid)
               {
                      if ($row['rid'] == $roleID)
                      {
                              $returnValue = true;
                              break;
                      }
               }
          }
          return $returnValue;
    }
    
    function enoughKarma()
    {
            if ( getKarma() >= $requiredKarma)
            {
                     return true;
            }
            else
            {
                    return false;
            }      
    }
    
    function buyRole()
    {
           $currentKarma = getKarma();
           $newkarma = $currentKarma - $requiredKarma;
           $userID = getUID();
           mysql_query("UPDATE userpoints SET points = '$newkarma' WHERE uid='$userID'");
           mysql_query("INSERT INTO users_roles (uid, rid) VALUES ($userID, $roleID)");
    }
    ?>
    
    <script type="text/javascript">
    buyItem(1 , 0);
    function SetStore()
    {
    
    
    }
    
    Function buyItem(itemID,reqKarma)
    {
           if (<?php enoughKarma(); ?>)
           {
                 <?php buyRole(); ?>
           }
           else
           {
                alert('You do not have enough Karma to buy this title.');
           }
    }
    </script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:33:47+00:00Added an answer on May 29, 2026 at 5:33 am

    PHP is a server side script and javascript is a client side, server side scripts are executed before the page loads, meaning your javascript cannot pass variables to it, BUT you can how ever pass php variables to your js.

    Best solution in your case is to use ajax to send those variables to php and have the php set variables on it’s side, this doesn’t quite solve your problem, but with some creativity in your code you can make it happen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have a big community website build in drupal, where the site has a
I have website build in php . I like the revision control system used
I have a publishing website build with MOSS 2007 and I need to get
I'm trying to build a website. I have it displaying correctly in every browser
I have to build a html website, which will contain about 50+ pages. The
I have a website project that I want to build using CruiseControl.net. On one
Currently I'm tasked with doing the daily build. We have an ASP.NET 2005 website
I'm trying to write a script to login to a Drupal website automagically to
I have a website built in Drupal and I have both the fbconnect module
I am trying to build a website consist of three pages but with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.