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

  • Home
  • SEARCH
  • 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 4239614
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:03:29+00:00 2026-05-21T03:03:29+00:00

Starred lines represent places where problem may be occurring due to my lack of

  • 0
  • Starred lines represent places where problem may be occurring due to my lack of knowledge of how HTML, JavaScript, and PHP interact

Here’s the situation:

I’m creating a game that uses JavaScript, and I’m trying to access player information (player’s name) from a database using PHP. In order to help me debug I’m not currently trying to access the database. Right now I’m just placing a variable within the PHP file to represent the information I’ll try to access in the future, a string, which is the player’s name. Access to the HTML file, JavaScript file, and PHP file goes as follows:

*Files are all kept on GoDaddy hosting in the same directory, the files being named:

index.html

milktruck.js

xml_http_request.php

.

The user visits the website, which accesses the JavaScript file using the following line of code:

    <script type="text/javascript" src="milktruck.js"></script>

The game starts and the user is presented with a game interface. At this point the user has not specified to enter multiplayer mode and therefore the line of JavaScript code that accesses the PHP variable and displays it has not fired.

*Nowhere in my JavaScript file or HTML file do I make reference to my PHP file, such as the reference made to the JavaScript file in the HTML file. Do I need to make reference to the PHP file? Does using xml_http_request.php make any difference?

I’ve tried adding the following line of code in my JavaScript file:

    var simple = '<?php echo $simple; ?>';

and the following in my PHP file:

    $simple = 'simple string';

but when I run the game and click on multiplayer mode instead of the string ‘simple string’ being displayed the string “php echo $simple;” is displayed (with all the other characters, Stack Overflow won’t let me put it in there). JavaScript is recognizing that PHP code as a string, not a line of code.

What’s wrong here?

Here’s a link to my game if you want to see for yourself. Just click on the “multiplayer mode” button below the screen.

http://alterearth.net

  • 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-21T03:03:30+00:00Added an answer on May 21, 2026 at 3:03 am

    You can make the PHP code echo the Javascript code with the variable in it.

    Example:

    echo "<script> var x = $variable; </script>";

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

Sidebar

Related Questions

I have a MDB (Message driven bean) that receives messages with String which represent
I was reading over http://android-developers.blogspot.com/2009/04/backward-compatibility-for-android.html But I'm really not grasping how to ignore certain
In commit messages there is a rule which says: Lines starting with '#' will
I would like to extract some lines from a text file, I have started
What is the difference between these 2 lines? Visually I haven't noticed anything different.
I started trying to play with Mono, mostly for fun at the moment. I
I started an application in Google App Engine right when it came out, to
I started using subversion for one of my projects and it would be absolutely
I started a Rails project recently and decided to use RESTful controllers. I created
I started programming C# applications when the 1.0 framework was first released. I worked

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.