Not displaying variables

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Not displaying variables

Postby PickleBranston » 13. February 2009 17:42

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
PickleBranston
 
Posts: 5
Joined: 16. January 2009 19:15

Re: Not displaying variables

Postby Izzy » 13. February 2009 23:33

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.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Re: Not displaying variables

Postby PickleBranston » 14. February 2009 16:05

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!
PickleBranston
 
Posts: 5
Joined: 16. January 2009 19:15


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 39 guests