-3

We were able to run it in our comp lab a while ago, but I don't know if I'm doing it wrong or something's missing on my desktop.

<!DOCTYPE html>
<html>
<body>

<form method="post" action="sample2.php">
Name: <input type="text" name="fname">
<input type="submit">

</form>
</body>
</html>

And then we used this to print the input on a different page -

<!DOCTYPE html>
<html>
<body>

<?php
$name = $_POST['fname'];
echo $name;
?>

</body>
</html>
4

2 回答 2

0

You have to use a webserver like XAMPP on your desktop and open the HTML using localhost://form.html for example

http://www.apachefriends.org/en/xampp.html

You should use the XAMPP Portable Lite version which has all you need but not too much

于 2013-10-07T12:21:38.457 回答
0

你的代码看起来很完美。但问题可能是您没有在像 Apache 这样的服务器上运行代码。

按照这个步骤..

1)安装(你可以从这里XAMPP下载xampp )

XAMPP 可在http://sourceforge.net/projects/xampp获得,它是一个开源安装程序,将安装 Apache、MySQL、PHP、Perl、phpMyAdmin 和 FTP 服务器。适用于 Linux、Solaris 和 Windows 系统

2)转到 XAMPP > htdocs > 创建文件夹(项目)

3)在项目文件夹中创建2个文件

索引.php

<!DOCTYPE html>
<html>
<body>

<form method="post" action="sample2.php">
Name: <input type="text" name="fname">
<input type="submit">

</form>
</body>
</html>

示例2.php

<!DOCTYPE html>
<html>
<body>

<?php
$name = $_POST['fname'];
echo $name;
?>

</body>
</html>

4)运行代码: -http://localhost/project

于 2013-10-07T12:27:02.393 回答