Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

HTML form and PHP

 
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,

I tried to create a simple HTML form to take two input fields but I am unable to display what is entered on this form.

Below is the code for HTML form:-

<html>
<body>

<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>

*************************
And below is the code to display the submitted data for  "welcome.php":-

<html>
<body>

Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

</body>
</html>

**********
But the problem is that when I am executing above first code after saving it in a notepad file on my computer desktop as ht2.html and opening it in chrome browser and then entering two input fields then clicking
'submit' button then i get output as below:-

<html>
<body>

Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

</body>
</html>

Ideally it should have shown what i entered on the web form why is it happening so?


Thanks
 
Saloon Keeper
Posts: 6448
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Report post to moderator
Two questions:

1) What's the URL of the HTML file?

2) What happens if you execute the PHP page directly (via the browser, rather than as the target of the from execution)? I suppose its URL would be something like http://localhost/welcome.php
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Report post to moderator
1)file:///C:/Users/ADMIN/Desktop/ht2.html

2)Error i get upon clicking this link is attached here :-http://localhost/welcome.php

What i did saved first code as 'ht2.html' and second code as 'welcome.php' on my desktop.


error.png
[Thumbnail for error.png]
 
John Ken
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Report post to moderator
..just for more clarification uploading screen shots 1st when i click on html file saved as ht2.html which is saved as a google chrome icon on my desktop and second screen shot once i enter some data in these 2 fields and then click submit button.


Thanks
HTML-clicking.png
[Thumbnail for HTML-clicking.png]
after-clicking-submit-button.png
[Thumbnail for after-clicking-submit-button.png]
 
Tim Moores
Saloon Keeper
Posts: 6448
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Report post to moderator

file:///C:/Users/ADMIN/Desktop/ht2.html


You need to connect to the page via the server. The URL should be something like "http://.../ht2.html";

"file:///"; URLs just read from the local file system without being processed by the server.

As the welcome.php, you need to figure out what its URL is. Obviously not http://localhost/welcome.php

3) What is the root URL of the server? http://localhost/? http://localhost:8080/? Something else?

4) In which directory did you put welcome.php?
 
Saloon Keeper
Posts: 12022
257
  • Mark post as helpful
  • send pies
  • Report post to moderator
You don't put those files on your desktop. You put them in their own folder under htdocs, such as
  • Xampp installation folder\htdocs\greeting\index.html and
  • Xampp installation folder\htdocs\greeting\welcome.php


  • If you do it like this, you can access your form through the URL http://localhost/greeting/index.html.
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    i nicely copied it in the location as shown in attached screen shot and from there i clicked on ht2.html google icon (which we say html file) and then put some data in these 2 fields and then clicked on 'submit' button
    then also same result.

    please find attached screen shot showing the location where i had installed xampp and sample place i copied this ht2.html and welcome.php files.

    saved-in-location.png
    [Thumbnail for saved-in-location.png]
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    ...sorry pasted these 'h2.html' and 'welcome.php' files in htdocs folder now. but same issue persists i mean no change in result .

    please refer attached screen shot for the location of these files.
    under-htdocs-folder.png
    [Thumbnail for under-htdocs-folder.png]
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    ..even created one folder v1 under htdocs folder and put these ht2.html and welcome.php files there still no change in result yet.
    please refer attached screenshot for the same.



    Thanks..
    folder-under-htdocs.png
    [Thumbnail for folder-under-htdocs.png]
     
    Tim Moores
    Saloon Keeper
    Posts: 6448
    158
    Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Which URLs did you use?
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    i am no sure what URLs am i supposed to use here and how to use what i understand is i simply need to click this ht2.html file from the mentioned folder location and then input data and then click submit button and then see the output.
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    I think You meant this URL here http://localhost/v1/h2.html

    but it is also giving error please refer attached screenshot for details.


    Thanks
    URL-error.png
    [Thumbnail for URL-error.png]
     
    Tim Moores
    Saloon Keeper
    Posts: 6448
    158
    Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
    • Mark post as helpful
    • send pies
    • Report post to moderator

    John Ken wrote: i understand is i simply need to click this ht2.html file from the mentioned folder location


    No. As I said, "file" URLs won't work. You need "http" URLs.
     
    Tim Moores
    Saloon Keeper
    Posts: 6448
    158
    Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
    • Mark post as helpful
    • send pies
    • Report post to moderator

    Tim Moores wrote:

    3) What is the root URL of the server? http://localhost/? http://localhost:8080/? Something else?

    4) In which directory did you put welcome.php?

     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    3) What is the root URL of the server? http://localhost/? http://localhost:8080/? Something else?


    Sorry ,I don't know how to check this?


    4) In which directory did you put welcome.php?


    I put welcome.php file as posted in my last post in htdocs folder i created v1 folder there i have kept it.
    do you want to see any modified screen shot for this location ?

    Thanks
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    it seems i have made some success if i enter localhost/v1 folder in my chrome browser's new tab then i get attached page results.

    local-host.png
    [Thumbnail for local-host.png]
    h2.html-selection.png
    [Thumbnail for h2.html-selection.png]
    submit-button-result.png
    [Thumbnail for submit-button-result.png]
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    before doing all this i just started xampp control panel and clicked on start button infront of Apache module.

    Now i have been able to process entered data of this 2 field form from HTML page and able to display it on browser as well so kindly advise me how could i progress further for my main problem so that I could first
    progress towards desktop app and once it is over i would want to progress for web app ,I have changed the sequence as though i have been trying hard but making success very slowly even to achieve very small small targets.

    Thanks..
     
    Tim Moores
    Saloon Keeper
    Posts: 6448
    158
    Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Good to hear that you're finally making progress. Now you can study the PHP API to learn how to write data to a file.
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Data can be written to a file using php  like below :-



    <?php
    echo file_put_contents("test.txt","Hello World. Testing!");
    ?>


    But how is it going to solve my main problem?


    Thanks
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 12022
    257
    • Mark post as helpful
    • send pies
    • Report post to moderator
    I think you need to clarify what your main problem is. You've been saying you want to modify an XML file, but I don't think that's really what you want to do.

    I *think* that you want to just modify some entries in a database, regardless of the format, and when you retrieve data from the web service, you want the response to be in XML. Please correct me if I'm wrong.
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    The problem is to create an web-page,form,that would accept specific input and generate
    an XML file from it.The form has to have the ability to add items in one particular section(where we can
    add additional streams) and give us the ability to remove streams as well.
    For each stream we must be able to attach a logo for that stream as well.

    Xojo or Php for this could be used,

    below is the sample XML file and Data Format.

    <?xml version="1.0" encoding="UTF-8" ?>
    <collectionList>
    <grid class="5ColumnGrid">
    <section>
    <lockup onselect="playMedia('https://player.vimeo.com/external/187143276.m3u8?s...')">
    <img src="/resources/images/lockups/shelf1.png" width="308" height="308" />
    <title class="showTextOnHighlight">Title 1</title>
    </lockup>
    <lockup onselect="playMedia('https://player.vimeo.com/external/184669023.m3u8?s...')">
    <img src="/resources/images/lockups/shelf2.png" width="308" height="308" />
    <title class="showTextOnHighlight">Title 2</title>
    </lockup>
    <lockup onselect="playMedia('https://player.vimeo.com/external/181758939.m3u8?s...')">
    <img src="/resources/images/lockups/shelf3.png" width="308" height="308" />
    <title class="showTextOnHighlight">Title 3</title>
    </lockup>
    <lockup onselect="playMedia('https://player.vimeo.com/external/180890459.m3u8?s...')">
    <img src="/resources/images/lockups/shelf4.png" width="308" height="308" />
    <title class="showTextOnHighlight">Title 4</title>
    </lockup>
    <lockup onselect="playMedia('https://player.vimeo.com/external/180014530.m3u8?s...')">
    <img src="/resources/images/lockups/shelf5.png" width="308" height="308" />
    <title class="showTextOnHighlight">Title 5</title>
    </lockup>
    <lockup onselect="playMedia('https://player.vimeo.com/external/178583018.m3u8?s...')">
    <img src="/resources/images/lockups/shelf6.png" width="308" height="308" />
    <title class="showTextOnHighlight">Title 6</title>
    </lockup>
    <lockup onselect="playMedia('https://player.vimeo.com/external/178457098.m3u8?s...')">
    <img src="/resources/images/lockups/shelf7.png" width="308" height="308" />
    <title class="showTextOnHighlight">Title 7</title>
    </lockup>
    <lockup onselect="playMedia('https://player.vimeo.com/external/177558935.m3u8?s...')">
    <img src="/resources/images/lockups/shelf8.png" width="308" height="308" />
    <title class="showTextOnHighlight">Title 8</title>
    </lockup>
    <lockup onselect="playMedia('https://player.vimeo.com/external/173738601.m3u8?s...')">
    <img src="/resources/images/lockups/shelf9.png" width="308" height="308" />
    <title class="showTextOnHighlight">Title 9</title>
    </lockup>
    <lockup onselect="playMedia('https://player.vimeo.com/external/187143276.m3u8?s...')">
    <img src="/resources/images/lockups/shelf2.png" width="308" height="308" />
    <title class="showTextOnHighlight">Title 10</title>
    </lockup>
    </section>
    </grid>
    </collectionList>
    </stackTemplate>
    </document>


    Thanks
     
    Tim Moores
    Saloon Keeper
    Posts: 6448
    158
    Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
    • Mark post as helpful
    • send pies
    • Report post to moderator
    I don't know what you mean by "my main problem", but you said that you need to create a file, and you have found out how to do that using PHP. It seems the path forward is pretty straightforward from there, no? You need to change the HTML to have 3 fields, and then use those to create a file containing valid XML from that. Once that works you can adapt the HTML page to have a variable number of fields, instead of always having 3. But that can come later, no need to complicate things at this point.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 12022
    257
    • Mark post as helpful
    • send pies
    • Report post to moderator

    John Ken wrote:The problem is to create an web-page,form,that would accept specific input and generate an XML file from it.


    I think it's not necessary to create a file, but you need to verify the actual requirement. An XML response from the service is probably enough.

    The form has to have the ability to add items in one particular section(where we can add additional streams) and give us the ability to remove streams as well.


    See, what I am getting from this is that you need to store the current entries somewhere (likely in a database) and then use the HTML form to update the entries. How the entries are actually stored doesn't matter, just that you can retrieve them in the correct format.

    I suggest that you first verify these requirements and then learn how to send an XML response from a PHP web service. Personally I would prefer to use an API that automatically converts PHP objects to XML, but maybe to learn the basics it might be a good idea to take a look at the XML Manipulation refs.

    Your next goal is to create some PHP classes that model your problem, create mock instances from them and convert them to XML.
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    "I don't know what you mean by "my main problem", but you said that you need to create a file, and you have found out how to do that using PHP.
    It seems the path forward is pretty straightforward from there, no? You need to change the HTML to have 3 fields, and then use those to create
    a file containing valid XML from that. Once that works you can adapt the HTML page to have a variable number of fields, instead of always having 3.
    But that can come later, no need to complicate things at this point."


    --->No, Sorry I have not been able to know yet that how can i create a file using PHP.
    So Far I just showed that I was able to create a HTML file and was able to enter data in it's 2 fields and then was able to display them on browser
    using PHP file.

    "I think it's not necessary to create a file, but could you please verify the actual requirement. An XML response from the service is probably enough."

    ...>Yes


    "See, what I am getting from this is that you need to store the current entries somewhere (likely in a database) and
    then use the HTML form to update the entries. How the entries are actually stored doesn't matter, just that you can retrieve them in the correct format."

    --->Yes, this could be a solution. But how could I create some PHP classes that model to my problem, create mock instances from them and convert them to XML


    Thanks
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 12022
    257
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Well, if I wanted to create a model for a hotel room booking application, I might write classes like this:


    By a mock instance, I mean something like this:

    And I'd probably convert it to XML like this:
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Thanks.

    Does below look in sync with my problem:-

    Classes:-


    for a mock instance like below for my problem:-




    For converting it to XML like below:-




    Thanks much..
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 12022
    257
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Well have you tried running it?
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    how can i run it,it seems to be java code?
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 12022
    257
    • Mark post as helpful
    • send pies
    • Report post to moderator
    How do you figure? Have you learned PHP yet?
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    No,Sorry but I am not sure how to compile this code in PHP ?
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    I used this link to run it online:https://rextester.com/l/php_online_compiler

    But it is not giving any useful output.,I just  tested first my code for classes with respect to modelling my main problem.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 12022
    257
    • Likes 1
    • Mark post as helpful
    • send pies
    • Report post to moderator
    You can't expect us to help you write and run a program if you're not willing to even learn the language. To write a PHP application you need to known PHP. So learn PHP now.
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    I am learning it as fast as possible but how can i compile all those classes,instances and then convert to XML code?

    When I will compile and execute it then only i will come to know whether my program is working as expected or not right?

    So Kindly advise accordingly.


    Thanks much..
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 12022
    257
    • Mark post as helpful
    • send pies
    • Report post to moderator
    PHP is not compiled. It's interpreted by the PHP executable. You don't need to call the PHP executable. Your PHP files are fed to it by Apache. So literally the only thing you need to do is stick your PHP files in a folder relative to the web root (htdocs) and they will get executed when you browse to them with an HTTP request. You've already seen this in action when your welcome.php file was executed.

    You keep asking how to do stuff. We keep telling your to read the manual. Read the manual.
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    I saved said code as additem.php,Convert to XML problem.php,mock instance of problem.php and my HTML form as form.html in same V1 folder from where earlier i had executed welcome php in my previous post.

    But this time When I am executing my HTML form page and click on submit button i can not see any effect of the coding for php files for above at all,kindly advise what is going wrong here?

    Thanks much..
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 12022
    257
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Don't know, because I don't know your code. You can use the echo() and var_dump() functions to debug your application by printing intermediate results.
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    My code:- for additem.php file



    my code for mocke instance of problem.php file:-




    my code for Convert to XML problem.php



    my code for HTML file:-  form.html



    So this is my code as mentioned above and I am not sure how could i  use the echo() and var_dump() functions to debug my application by printing intermediate results.Kindly advise...


    Thanks much...
     
    Tim Moores
    Saloon Keeper
    Posts: 6448
    158
    Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
    • Mark post as helpful
    • send pies
    • Report post to moderator

    I am not sure how could i  use the echo() and var_dump() functions to debug my application


    You can find out by using any number of freely available online resources that teach you PHP. Asking questions here any time you get stuck is not a sustainable learning strategy in a reasonable time, and most likely not at all, because no one here is willing to teach you PHP if you're not willing to do any work to learn it yourself.
     
    John Ken
    Ranch Hand
    Posts: 388
    • Mark post as helpful
    • send pies
    • Report post to moderator
    ok,but where all i need to debug at least i should know this right and where should i put that debug and where is the problem,i have already designed HTML page but now i am stuck with clicking on submit button nothing happens when i click on submit button where as i hve written code for additem,mock instance and convert to xml also not sure where to correct and what to correct to resove my issue at the earliest now?

    Thanks much..
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 12022
    257
    • Mark post as helpful
    • send pies
    • Report post to moderator
    You are not submitting your form to any specific action.
     
    What's gotten into you? Could it be this tiny ad?
    Devious Experiments for a Truly Passive Greenhouse!
    https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
      Bookmark Topic Watch Topic
    • New Topic