Form does not send data

Asked

Viewed 375 times

0

I am trying to make the data typed by the user appear on another page when he clicks the button only the page is updated but does not contain the information typed.

HTML file

 <form action="php/dados.php" method="post">

        <input type="text" id="cNome" name="tNome" size="20" maxlength="20" placeholder="       Digite Seu Nome"/>
     <input type="submit" value="Enviar"/>
    <input type="reset" value="Cancelar"/>
  </form>

PHP file

<?php

    $nome = $_POST["tNome"];
    echo "Obrigado $nome";
?>

I’ve looked over and over but I can’t find the error,?

  • 1

    Do not use stacksnippets (code snippets) unnecessarily, they are not to format but to execute js+css+html codes that do something, if not to do anything use the normal dialing.

1 answer

2


You must be using or protocol file:/// instead of http:// (for example accessed file:///c:/Users/Lone/Documents/projeto/form.php instead of http://localhost/form.php) or you must be using Apache without PHP.

As I explained here /a/62797/3635, if it is Windows install or Xampp or Wamp or easyphp

If you have already installed it is because you may be accessing something like this from the browser file:///c:/wamp/www/form.php, see if the URL in the browser "like" with this:

url navegador

This won’t work, the file protocol is to run local files, Apache is a server, even if local and you need to run through it.

After installing Xampp, Lamp (linux), Wamp, Mamp (Mac OSX), you should copy your files to the following "possible" folders (these folders are for example, but the path should be similar):

  • Windows and Wamp: c:/wamp/www
  • Windows and Xampp: c:/xampp/htdocs
  • Linux and Lamp/Xampp: /otp/lamp/htdocs
  • Linux installed via repository: /var/www

Of course it is possible to point out other folders, but this is another story.

  • So in case I need to show this file to someone without letting online will not be possible ?

  • 1

    @Lonetonberry if it is not "online" has no way to see, after all it is online right? Now Xampp, Wamp, http://localhost, etc has nothing to do with "online", they only run on your machine and this is used for you to develop your pages and scripts. Now if you want to remotely display to someone the page you can put in a hosting (should be the online that refers) or try to use no-ip, this should help: external access with wamp

  • I meant that I will need to take this work to another machine, but I don’t want to leave the site online.So in case I would have to have installed on that machine these programs too or not ?

  • 1

    @Lonetonberry that’s right, has to be installed, so we call it a development environment, there is no way to create a PHP script without having the PHP program (it comes together with Xampp or Wamp, or others, just need one of them), there is also no way to run a PHP script for HTTP server without an HTTP server on the machine. Xampp and others have Apache (server) and PHP (interpreter), just install, if not they would be the same as wanting to edit an Msword (.doc and .docx) file without having Office 2007 or Office 365 installed.

  • So that means that the correct thing would be for me to take all my HTML, JS, CSS , PHP files and throw them into the respective program folders ?

  • 1

    @Lonetonberry yes php scripts only run if you have the PHP program and Apache needs a default folder. Files . php are created to run on websites and these sites use a server such as Apache, Nginx, Lighttpd, etc. These servers have to have a folder where it is where the data going to the site would be, as I said files. php need the php.exe program, not having it is like trying to edit a . doc without having the Office, I recommend reading this http://answall.com/a/115690/3635

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.