5

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. So I installed Apache and then PHP on my local PC and expected to be able to test a PHP script locally however it does not return the information I was expecting. The following 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> 

The following is the code for the 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 it works when used on the internet but how come it doesn't work locally. I have checked that apache and php are installed correctly. What could be the issue? The current result is a table with $key and $value in the places where the correct values should be, in other words in the table cells. Thanks for your help.

UPDATE: Now working though WAMPSERVER- thanks to all who helped!

4
  • Is PHP being processed at all, or is your script not working as you expect it to? Try creating a PHP file with the contents: <?PHP phpinfo(); ?> Commented Jan 14, 2009 at 19:44
  • <?PHP phpinfo(); ?> does result in a page of information about php setup being returned. The problem is getting the values from the form into the table on the separate web page when being tested locally. Commented Jan 14, 2009 at 21:46
  • Which PHP version are you using? Commented Jan 14, 2009 at 22:33
  • I was using PHP version 5.2.8, however I have just uninstalled both PHP and Apache, and installed XAMP as some people have suggested here, but whereas before the phpinfo returned info now it does not with XAMP. Commented Jan 14, 2009 at 22:40

5 Answers 5

7

Check out xampp. It installs Apache, Mysql, Perl, and PHP on your machine so you can test your entire site locally. It's a one shot installer and comes with a nifty control panel to enable/disable each service as needed.

Sign up to request clarification or add additional context in comments.

Comments

3

You could also try WampServer.

It's a package containing: Apache, MySQL, PHP (Preconfigured for use in Windows).

1 Comment

Thank you I got it working through WampServer. Much appreciated!
2

There's no need for a server if 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

Comments

0

Sounds like your PHP script isn't being parsed if you're literally getting $value. Try running a basic phpinfo() to check this.

If PHP doesn't pick that up make sure the path to PHP is set in httpd.conf. I'd reccommend using xampp though - I'm terrible at all the local configuration and just let the auto installer set it up for me. I know enough to add new modules etc. later on.

Comments

-2

On first glance, it looks like you're trying to place variables, but you're putting the variables inside of a string.

So this:

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

Should be something like:

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

1 Comment

This is incorrect. If a variable is seen in a double-quoted string, it is inserted in the string as you'd expect. If a single-quote were used, the string would need to be split as you have shown.