Join us on Discord!
You can help CodeWalrus stay online by donating here.

Best programming language for server-side web programming

Started by Ephraim Becker, November 13, 2015, 08:01:23 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

DarkestEx

Quote from: Ephraim Becker on November 15, 2015, 12:59:03 AM
Should I turn my existing HTML into a PHP or should I create a separate PHP?
Both would work. But I guess keep them seperate.
  • Calculators owned: TI-84+, Casio 101-S, RPN-Calc, Hewlett-Packard 100LX, Hewlett-Packard 95LX
  • Consoles, mobile devices and vintage computers owned: Original Commodore 64C, C64 DTV, Nintendo GameBoy Color, Nintendo GameCube, Xbox 360, PlayStation 2

Ephraim Becker

Is it best to put the PHP file in another folder or in the same directory as the HTML?
  • Calculators owned: TI 84 Plus, TI 84 Plus C Silver Edition, TI 84 Plus CE, Casio FX-9750 GII
I have Aspergers Syndrome

DarkestEx

Quote from: Ephraim Becker on November 15, 2015, 01:05:38 AM
Is it best to put the PHP file in another folder or in the same directory as the HTML?
Same directory is better though it doesn't really matter.
  • Calculators owned: TI-84+, Casio 101-S, RPN-Calc, Hewlett-Packard 100LX, Hewlett-Packard 95LX
  • Consoles, mobile devices and vintage computers owned: Original Commodore 64C, C64 DTV, Nintendo GameBoy Color, Nintendo GameCube, Xbox 360, PlayStation 2

Ephraim Becker

I have my CSS, JavaScript, and images each in a separate folder and I have my HTML as the root of my webpage project. Should my PHP go in it's separate folder also?
  • Calculators owned: TI 84 Plus, TI 84 Plus C Silver Edition, TI 84 Plus CE, Casio FX-9750 GII
I have Aspergers Syndrome

DarkestEx

Quote from: Ephraim Becker on November 15, 2015, 01:19:21 AM
I have my CSS, JavaScript, and images each in a separate folder and I have my HTML as the root of my webpage project. Should my PHP go in it's separate folder also?
You decide. Either same folder or folder below it.
  • Calculators owned: TI-84+, Casio 101-S, RPN-Calc, Hewlett-Packard 100LX, Hewlett-Packard 95LX
  • Consoles, mobile devices and vintage computers owned: Original Commodore 64C, C64 DTV, Nintendo GameBoy Color, Nintendo GameCube, Xbox 360, PlayStation 2

Ephraim Becker

#20
How do I link the PHP to my other website files?

Update: I don't think I can do that. I have to turn index.html into index.php

Update 2: I think all I need to do is link the PHP to the JavaScript
  • Calculators owned: TI 84 Plus, TI 84 Plus C Silver Edition, TI 84 Plus CE, Casio FX-9750 GII
I have Aspergers Syndrome

alexgt

  • Calculators owned: Ti-84+, Ti-Nspire, Hp Prime, Broken HP Prime, HP 48SX

Ephraim Becker

#22
The JavaScript file is interpreting the PHP file as undefined:

PHP code:
<?php$url = "http://www.winbeta.com/feed";$str = file_get_contents ($url);echo "Testing";?>


JavaScript code:
function technology()
{
    personTwoSays.value = "";
    submitButtonThree.style.display = "none";

    var submitButtonFour = document.createElement("button");

    submitButtonFour.innerHTML = "Submit";
    personTwoTalk.appendChild(submitButtonFour);
    personTwoSays.setAttribute("placeholder", "Type reply...");

//Get the latest technology news from the internet
function fetchLatestNews()
{
    var request = new XMLHttpRequest();

    request.open("GET", "../php/news.php");
    request.send();
};

    personOneTalk.innerHTML = "Sure! Have you heard of " + fetchLatestNews();
};
  • Calculators owned: TI 84 Plus, TI 84 Plus C Silver Edition, TI 84 Plus CE, Casio FX-9750 GII
I have Aspergers Syndrome

DarkestEx

#23
Quote from: Ephraim Becker on November 15, 2015, 02:50:10 AM
The JavaScript file is interpreting the PHP file as undefined:

PHP code:
<?php
$url = "http://www.winbeta.com/feed";
$str = file_get_contents ($url);

echo "Testing";
?>

JavaScript code:
function technology()
{
personTwoSays.value = "";
submitButtonThree.style.display = "none";

var submitButtonFour = document.createElement("button");

submitButtonFour.innerHTML = "Submit";
personTwoTalk.appendChild(submitButtonFour);
personTwoSays.setAttribute("placeholder", "Type reply...");

//Get the latest technology news from the internet
function fetchLatestNews()
{
var request = new XMLHttpRequest();

request.open("GET", "../php/news.php");
request.send();
};

personOneTalk.innerHTML = "Sure! Have you heard of " + fetchLatestNews();
};
Go for json after all:

Php: print(json_encode(array("ab"=>123)));

JavaScript: JSON.decode(string)

Edit how are your files placed in folders? Which file is where?
  • Calculators owned: TI-84+, Casio 101-S, RPN-Calc, Hewlett-Packard 100LX, Hewlett-Packard 95LX
  • Consoles, mobile devices and vintage computers owned: Original Commodore 64C, C64 DTV, Nintendo GameBoy Color, Nintendo GameCube, Xbox 360, PlayStation 2

Ephraim Becker

index.html is at the root of the project folder. The JavaScript file is in the js folder and the PHP file is in the php folder.
  • Calculators owned: TI 84 Plus, TI 84 Plus C Silver Edition, TI 84 Plus CE, Casio FX-9750 GII
I have Aspergers Syndrome

DarkestEx

Quote from: Ephraim Becker on November 15, 2015, 03:04:55 AM
index.html is at the root of the project folder. The JavaScript file is in the js folder and the PHP file is in the php folder.

Try to do php/ instead of ../php/
I don't know if it will fix it.
  • Calculators owned: TI-84+, Casio 101-S, RPN-Calc, Hewlett-Packard 100LX, Hewlett-Packard 95LX
  • Consoles, mobile devices and vintage computers owned: Original Commodore 64C, C64 DTV, Nintendo GameBoy Color, Nintendo GameCube, Xbox 360, PlayStation 2

Ephraim Becker

No. It doesn't fix the problem. It still says undefined.
  • Calculators owned: TI 84 Plus, TI 84 Plus C Silver Edition, TI 84 Plus CE, Casio FX-9750 GII
I have Aspergers Syndrome

jacobly

It says undefined because fetchLatestNews() doesn't return anything and functions that don't return anything return undefined.  You probably want to add an event listener for the load event to request so you can display the result of the request.

Ephraim Becker

#28
How do I make my function return the output of the PHP file?
  • Calculators owned: TI 84 Plus, TI 84 Plus C Silver Edition, TI 84 Plus CE, Casio FX-9750 GII
I have Aspergers Syndrome

jacobly

Something like:
Code (JavaScript) Select
function technology()
{
    personTwoSays.value = "";
    submitButtonThree.style.display = "none";

    var submitButtonFour = document.createElement("button");

    submitButtonFour.innerHTML = "Submit";
    personTwoTalk.appendChild(submitButtonFour);
    personTwoSays.setAttribute("placeholder", "Type reply...");

//Get the latest technology news from the internet
function fetchLatestNews()
{
    var request = new XMLHttpRequest();
    request.addEventListener("load", handleResponse);
    request.open("GET", "php/news.php");
    request.send();
}

function handleResponse() {
    personOneTalk.innerHTML = "Sure! Have you heard of " + this.responseText;
}

    fetchLatestNews();
};


Edit: In response to your edit, you can't really return the result of an asynchronous request in javascript.

Powered by EzPortal