Reputation: 500
I'm really struggling to get my .php page to successfully post data to the next php page. Everywhere I look, it seems as though I am doing exactly what they suggest, so I am completely lost as to why my code is not working.
Index.php
<form action="submit.php" method="post">
<ol>
<li>What is your gender?
<ul>
<li>
<input type="radio" name="gender" value="male">Male
<input type="radio" class="space" name="gender" value="female">Female
<input type="radio" class="space" name="gender" value="other">Other
</li>
</ul>
</li>
</ol>
<input type="submit" name="submit" id="submit" value="Submit">
</form>
submit.php
<html>
<body>
<h1>Thank you!</h1>
<p><?php echo $_POST["gender"]; ?></p>
</body>
</html>
This is a much more shortened version of what I have, but when I enter values into the form and hit 'Submit', it DOES direct to the other PHP page, but I'm not able to access any of the form values.
Upvotes: 0
Views: 66
Reputation: 409
Your code is fine. It does not work because you need a server to run PHP locally. You need a server to handle HTTP requests and PHP installed on your PC to work local.
There is a complete solution called AMPPS. AMPPS installs Apache Server, PHP, MySQL and more.
When you install and run AMPPS, the server starts. Now you need to create a folder in this direction to place your project:
C:\Program Files (x86)\Ampps\www
Now place both index.php and submit.php to the folder you created. So if you named your folder, for example, "mysite", you can go to your website using this url in your browser:
http://localhost/mysite/
All done. You are ready to code.
In case you need a database, you can go to this link to use phpMyAdmin and of course you should write some PHP code to connect database:
http://localhost/phpmyadmin/
Have fun!
Upvotes: 1