Page 1 of 1

Not displaying variables

PostPosted: 13. February 2009 17:42
by PickleBranston
Hi,

Trying to leran php at the moment, after a several bits of code i wrote not working i have copied a few bits of exemplar code in, and they still do not work.
Basically all text is displayed from a php print command, however variable values are not. Here is an example of what i mean....


All files are within xampp/htdocs/folder and apache is running.

page.html
Code: Select all

<form action="page.php" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>



page.php
Code: Select all
<p>
Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old.
<p>


and this displays;

Welcome .
You are years old.




This is sample code from w3schools.com

Re: Not displaying variables

PostPosted: 13. February 2009 23:33
by Izzy
I copied and pasted your code into a blank page in my text editor and then saved the file as form.html in the xampp\htdocs folder.

I copied and pasted into a blank page in my text editor the php code and saved it as form.php again into the xampp\htdocs folder - make sure you are using a text editor not a RTF editor and you save as text not as UTF-8 or any other encoding.
Unicode FAQ for UTF-8, UTF-16, UTF-32 & BOM (Byte Order Mark)

I typed in the browser http://localhost/form.html and proceeded to enter data into the name and age fields, then clicked on Submit Query button.

The variables name and age had been added successfully.
Welcome Izzy.
You are nearly 2000 years old.
So your pasted code works fine.

Re: Not displaying variables

PostPosted: 14. February 2009 16:05
by PickleBranston
I see my problem now, i was just double clicking on form.html, so it opened on a page C:/etc/etc/form.html rather than localhost/.... forcing it to go through the localhost obviously fixed it.

Sorry about that as i am only new to this but thanks for the help!