如何在PHP中正确传递表单数据? [英] How to properly pass form data in php?

查看:92
本文介绍了如何在PHP中正确传递表单数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用php构建了一个小型表单,需要传递2个变量进行处理。

I'm using php to build a small form that requires passing 2 variables for processing.

我得到了w3schools的示例,尽管信息通过了URL,PHP表单不会以任何方式处理它(更不用说提取它了)。

I got the example off w3schools and although the info gets passed in the URL, the php form doesn't process it in any way (let alone extract it).

我只是想知道我的WAMP服务器可能有什么问题。

I'm just wondering if there might be anything wrong with my WAMP server.

    <html>
    <body>
    welcome
    Welcome <?php echo $_GET["fname"]; ?>.<br />
     You are <?php echo $_GET["age"]; ?> years old!
    </body>
    </html> 

HTML表单:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://        www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html;                 charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <form action="welcome.php" method="get">
     Name: <input type="text" name="fname" />
     Age: <input type="text" name="age" />
     <input type="submit" />
     </form>
    </body>
    </html>


推荐答案

事实上,工作。
根据我的经验,如果php标签没有被解析,它们会直接输出。
您是否看到网页上的任何内容?您也可以检查页面的源代码,并检查是否可以发现任何错误。

Indeed as already noted by various posts, this code should work. In my experience the php tags are output directly if they're not parsed. Do you see anything on the page at all? You could also check the sourcecode of the page and check if you can spot anything wrong there.

另外,当从互联网上的例子复制时,有时会出现奇怪的字符,解析器。通常这会导致一个错误(这里不是这种情况),但检查没有任何坏处。

Also when copying from examples on the internet, sometimes you get weird characters that interrupt the parser. Usually this results in an error (which is not the case here), there's no harm in checking though.

试着输出一些简单的东西,看看它是否有效:

Try outputing something simple and see if that works:

<?php echo "Hello World"; ?>

目前无法想到其他任何东西......

Can't think of anything else at the moment...

这篇关于如何在PHP中正确传递表单数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆