0

I am new web development,I am trying to use Html,Java script and php together. See the code below...

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
            function sayHello()
            {
                alert("Hello World!");
            }
        </script>
    </head>
    <body>
        <h3>Good Evening Friends</h3>
        <?php
            echo "Inside php script";
        ?>
        <form>
            <input type="Button" name="B utton" value="b utton" onclick="sayHello()"/>
        </form>
    </body>
</html>

The above code when run on xampp server is not producing the expected result, the code inside php script is not printed why? If I am using wrongly tell the correct useage?

Also tell me which server side language and date base to use if javascript and html are used for front end?

3 Answers3

1
  1. Please make sure your file extension is .php , eg index.php
  2. Please save the .php file into xampp -> htdocs
  3. Use http://localhost/ to load your webpage

:) Hope this can help you

Ah Dii
  • 48
  • 7
1

HI..

  1. Make sure your file extension is .php
  2. You can also do this:

<!DOCTYPE html>
<html>

<head>
  <script type="text/javascript">
    function sayHello() {
      alert("Hello World!");
    }
  </script>
</head>

<body>
  <h3>Good Evening Friends</h3>
  <?php 
  //funziona
            $hello = "PHP onboard!";
            echo "<br>".$hello."<br>";
  ?>

  <form>
    <input type="Button" name="Button" value="b utton" onclick="sayHello()" />
  </form>
</body>

</html>
  1. I suggest to you to use Altervista for write php code (In Altervista the code run exatly... good job)

good luck

by Alessandro

Mr X
  • 139
  • 2
  • 15
  • 1
    ok I got , It is running correctly. many say that javascript can be used for both front end and back end. I don't know about back end (java script), how to use it.In tutorials point they did not mention anything about database connection using javascript? tell me what exactly should I learn to use javascript for back end? – rajshekhar y dodamani Jun 05 '18 at 14:24
  • Some people will tell me that there are some other things to learn, but i think that you should start to study MYSQL or Node JS... These are back end programs and can help you in everything... – Mr X Jun 05 '18 at 14:46
  • Node js use javascript as language for program as server side – Mr X Jun 05 '18 at 14:47
  • **_write me_ if it was useful for you** – Mr X Jun 05 '18 at 15:11
0

1) your file need have extension .php

2) if you use, Xampp, your url must begin localhost or 127.0.0.1 or name in hosts

Andrey Matveev
  • 125
  • 1
  • 7