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] <?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. I have also tried using XAMPP as well. Thanks for your help. Code (markup):
If you installed apache or php wrong, it could be causing problems. Try setting up a localhost. http://www.wampserver.com It is very helpful, and runs exactly like a web server would.
my .02 cents. i used to develop on my local and move working code to the server. i finally got tired of spending hours making something work on my local, only to find out the local server / hosting server are different OR different version of php. so, i NEVER develop local anymore its not worth my time do REDO my code for the hosting server
That is why you must keep your software up to date I've never had any problems moving from localhost to online. If you set things up properly, All you will need todo is fix the sql connection settings when you move it, and make sure you move your db's and all, and you should be set.
No problem. Also, you are using a very weird way to print your form results on the next page. You can just use something like echo $_POST['field_name'] unless you have some other reasons to be doing it that way, if so, don't mind me enjoy
its been a few years ago, that i stopped developing local. ps. i know from chaning hosting companies.... 2 servers that were supposed to be the same, well, there are differences.... in settings, in paths, in minor things ..... the more advanced coding you have... the more these small details come into play
Personally, I hand roll everything (install php, apache and mysql by hand and tie them together so I can customize everything) but for beginners that can be a nightmare. I recommend using Zend Core: http://www.zend.com/products/core/ It installs everything for you, ties it all together and gives you a little management console. Best of all, it's 100% free. I would recommend it for any new developers wanting to run php scripts. Combine this with Notepad++ and you have everything you need to start php development, for free!
u can use XAMP or WAMP server it contains Apache + php + mysql all u need to run ur site on ur local pc..
No offence intended but your code must be pretty poor if you need to change that much. Assuming your server has at least PHP 5, preferably 5.2+ (and if they didn't, why would you host with someone who can't keep their free software up to date?) then there's next to nothing that would need alterating between local and server. I personally write everything locally, all I have to change is the database details and a few lines in a config file and everything works perfectly. Dan.
php not installled properly....i think it just came as text dowciments....download wampserver or xamp,they will install php,mysql...etc in a single click
You need to add a directive in http.conf http://httpd.apache.org/docs/1.3/mod/mod_mime.html#addhandler