tags:

views:

360

answers:

4

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!

+6  A: 

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.

ryeguy
A: 

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.

Ross
A: 

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";

I'm newb, so don't rail me if I'm wrong, pls thx.

lush
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.
strager
+1  A: 

You could also try WampServer.

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

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