Testing PHP script on local computer

New to PHP and web development in general. I am trying to get information from an HTML form to appear in a table on another web page after clicking submit. Therefore, I installed Apache and then PHP on my local PC and expected to be able to test the PHP script locally, but it does not return the expected information. Below is the code for the form:

<form method="post" action="showform.php">

Please fill out the following form if you would like to be contacted: <br/>
    Name:<input type="text" name="name" /> <br/><br/>
    Company: <input type="text" name="company"/> <br/><br/>
    Phone: <input type="text" name="phone" /> <br/><br/>
    Email: <input type="text" name="email" /> <br/><br/>

    <input type="submit" name="Submit" value="Submit" />
</form>

Below is the code for php script:

<table>
<tr><th>Field Name</th><th>Value(s)</th></tr>

<?php
if (empty($_POST)) {
print "<p>No data was submitted.</p>";
 } else {

foreach ($_POST as $key => $value) {
if (get_magic_quotes_gpc()) $value=stripslashes($value);
if ($key=='extras') {

if (is_array($_POST['extras']) ){
    print "<tr><td><code>$key</code></td><td>";
    foreach ($_POST['extras'] as $value) {
            print "<i>$value</i><br />";
            }
            print "</td></tr>";
    } else {
    print "<tr><td><code>$key</code></td><td><i>$value</i></td></tr>\n";
    }
} else {

print "<tr><td><code>$key</code></td><td><i>$value</i></td></tr>\n";
}
 }
}
?>
</table>
</body>
</html>

I know this works when used on the Internet, but why it doesn't work locally. I checked that apache and php are installed correctly. What could be the problem? The current result is a table with the $ key and the $ value in places where the correct values ​​should be, in other words, in the table cells. Thank you for your help.

UPDATE: now works, although WAMPSERVER- thanks to everyone who helped!

+5
5

xampp. Apache, Mysql, Perl PHP, . / .

+7

WampServer.

, : Apache, MySQL, PHP ( Windows).

+3

, PHP script , $value. phpinfo(), .

PHP , , PHP httpd.conf. xampp, - . , .. .

0

There is no need for a server when using PHP 5.5+ - it has a built-in server ( http://www.php.net/manual/en/features.commandline.webserver.php )

Just use:

$ cd ~ / project

$ php -S localhost: 8000

0
source

At first glance, it looks like you are trying to place variables, but you are putting variables inside a string.

So this is:

print "<tr><td><code>$key</code></td><td><i>$value</i></td></tr>\n";

It should be something like:

print "<tr><td><code>" . $key . "</code></td><td><i>" . $value . "</i></td></tr>\n";
-2
source

All Articles