HTML表单POST为空 [英] HTML Form POST is null

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

问题描述

所以我试图简单地将一个数据字段从一个表单发送到一个php文件。以下是我的表格。我也发布了我的PHP代码。它一直返回$ username为空。我试过后/得到,它似乎并不重要。



HTML:

 < form action ='http://k9minecraft.tk/scripts/adduser.php'method ='POST'> 
< table>
< tr>
< td>名字:< / td>
< td>< input type ='text'id ='first'>< / td>
< / tr>
< tr>
< td>姓氏:< / td>
< td>< input type ='text'id ='last'>< / td>
< / tr>
< tr>
< td>电子邮件地址:< / td>
< td>< input type ='text'id ='email'>< / td>
< / tr>
< tr>
< td> Minecraft名称:< / td>
< td>< input type ='text'name ='user'>< / td>
< / tr>
< tr>
< td>< input type ='submit'value ='发送'>< / td>
< td>< input type ='reset'value ='重置'>< / td>
< / tr>
< / table>
< / form>

PHP:

 <?php 
print_r($ _ POST);
if(isset($ _ POST ['user'])){
$ username = $ _POST ['user'];
echo $ username;
echo'username is not null';
}
?>


解决方案

此代码正在工作。如果 $ username 被张贴或不张贴,您需要添加一些条件。



类似这样的:

  if(count($ _ POST)){
$ username ='';
if(isset($ _ POST ['user'])){
$ username = $ _POST ['user'];
if($ username == null ||!$ username)
echo'username is null';
echo strlen($ username);
echo $ username;
}

}


so I'm trying to simply send one field of data from a form to a php file. Below is my form in a table. I also posted my php code. It keeps returning that $username is null. Ive tried post/get and it doesn't seem to matter.

HTML:

<form action='http://k9minecraft.tk/scripts/adduser.php' method='POST'>
<table>
<tr>
<td>First Name:</td>
<td><input type='text' id='first'></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type='text' id='last'></td>
</tr>
<tr>
<td>Email:</td>
<td><input type='text' id='email'></td>
</tr>
<tr>
<td>Minecraft Name:</td>
<td><input type='text' name='user'></td>
</tr>
<tr>
<td><input type='submit' value='Send'></td>
<td><input type='reset' value='Reset'></td>
</tr>
</table>
</form>

PHP:

<?php
print_r($_POST);
    if(isset($_POST['user'])){
        $username = $_POST['user'];
        echo $username;
        echo 'username is not null';
        }
?>

解决方案

This code is working. You need to add some condition, that checks, if $username is posted or not.

Something like that:

if(count($_POST)){
    $username ='';
    if(isset($_POST['user'])){
        $username = $_POST['user'];
    if ($username==null || !$username)
         echo 'username is null';
     echo strlen($username);
     echo $username;
   }

 }

这篇关于HTML表单POST为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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