在php上回显我的表单值 [英] echo my form values on php

查看:65
本文介绍了在php上回显我的表单值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的代码来打印插入框中的值。然而,当我把值,然后点击提交没有打印出来。

 < html> 
< body>

< form action =<?php $ _SERVER ['PHP_SELF']?>方法= POST >
名称:< input type =textname =name>< br>
电子邮件:< input type =textname =email>< br>
< input type =submit>
< / form>

<?php
if(isset($ _ POST [submit])){
$ name = filter_input(INPUT_POST,'name');
$ email = $ _POST ['email'];
echo $ name;
echo $ email;
}

?>
< / body>
< / html>

关于下面我试过这两种情况,因为在简单的$ _POST ['email']警告:

  $ name = filter_input(INPUT_POST,'name'); 
$ email = $ _POST ['email'];

警告:


直接访问超全局$ _POST数组


我使用Netbeans IDE 8.2。
<

  if(isset($ _POST [submit])){

改为:

  if(count($ _ POST)> 0){

您没有任何匹配 name =submit的元素。另外,使用 isset($ _ POST [submit])是一种不好的做法,因为我们很多人都不会将其命名。



如果您想检查设置的具体内容,您需要执行以下操作:

 <$ c $ ($ _ POST ['email'])){

如果你还想让你的代码在上面的设置中工作,请添加一个 name
$ p $ < code>< code>< code>< input type =提交name =submitvalue =提交/>


Am using the code below in order to print the values that am inserting on the boxes. However After I put the values and click submit nothing is printing out.

<html>
<body>

<form action="<?php $_SERVER['PHP_SELF']?>" method="post">
 Name: <input type="text" name="name"><br>
 E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

<?php
if(isset($_POST["submit"])) {
$name = filter_input(INPUT_POST, 'name');
$email = $_POST['email'];
echo $name;
echo $email;
}

?>
</body>
</html>

About below I tried both cases because on the simple one $_POST['email'] I was getting a warning:

$name = filter_input(INPUT_POST, 'name');
$email = $_POST['email'];

Warning:

Do not Access Superglobal $_POST Array Directly

I am using Netbeans IDE 8.2.

解决方案

This is never set:

if (isset($_POST["submit"])) {

Instead change it to:

if (count($_POST) > 0) {

You don't have any elements matching name="submit". Also, it is a bad practise to use isset($_POST["submit"]) as many of us, won't name it.

If you want to check for specific things set, like in your case, you need to do:

if (count($_POST) > 0 && isset($_POST["name"]) && isset($_POST['email'])) {

If still you wanna make your code work with the above set-up, kindly add a name and value here:

<input type="submit" name="submit" value="Submit" />

这篇关于在php上回显我的表单值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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