Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么';我的PHP不能处理简单的表单提交吗?_Php_Html_Forms - Fatal编程技术网

为什么';我的PHP不能处理简单的表单提交吗?

为什么';我的PHP不能处理简单的表单提交吗?,php,html,forms,Php,Html,Forms,我一直在为我的网站注册页面 下面是注册表的HTML代码和表单 <form action='' method='POST'> <table cellspacing='0' cellpadding='0'> <tr> <td valign='top'> <input type='text' name='Username' id='Username' placehold

我一直在为我的网站注册页面

下面是注册表的HTML代码和表单

<form action='' method='POST'>
    <table cellspacing='0' cellpadding='0'>
        <tr>
            <td valign='top'>
                <input type='text' name='Username' id='Username' placeholder='Enter your username.'>
            </td>
            <td valign='top'>
                <input type='submit' name='Submit' id='SubmitRegister' value=''>
            </td>
        </tr>
    </table>
    <font style='font-size:13px;color:#aaa;'>3-20 alphanumeric characters - no spaces</font>
</form>
但是,单击我的提交按钮后,什么也没有发生。我让它在$Submit上做这件事-

if ($Submit) {
    echo "Test";
}
我发现了一个问题,使用下面的函数secure()会阻止它工作,因为mysql\u real\u escape\u string()需要一个有效的数据库连接(已修复)

下面是函数

function secure($value) {
    $value = mysql_real_escape_string(strip_tags(stripslashes($value)));
    return $value;
}

我可能只是忽略了一个简单的错误,但这让我很恼火,让我耽搁了好几天。提前感谢。:)

提交按钮上的
value
属性需要实际值,或者您可以执行
isset($submit)
提交按钮的值是“”,因为您说
value='
。这是您在此处读取的值:
$Submit=secure($\u POST['Submit'])

这是一个空字符串。空字符串的计算结果为false。因此,
if($Submit)
检查返回false,并且不执行

通常不使用提交按钮的值。而检查通常是通过检查是否给出了用户名来完成的

if ( isset( $_POST['Username'] ) ) { ... }
你必须使用

if(isset($_POST['Submit']))
而不是

if ($Submit) 

你在表格里有个简单的错误。提交按钮值为空,您正在代码中使用它。对于您的if条件,它总是返回
false

更改:

<input type='submit' name='Submit' id='SubmitRegister' value=''>

致:



享受。

第一个错误是使用mysql_*函数,因为它们已被弃用。改用PDO或mysqli。为什么需要“筛选”提交?你的
secure
函数毫无意义。在将值放入该上下文时,对其应用上下文相关的转义措施。如果您的目的是将这些字符串保存到MySQL数据库中,只需使用
MySQL\u real\u escape\u string()
,并在从数据库中渲染它们时使用
htmlentities()
。感谢dude,这完美地修复了它。永远不会看到。永远不要忘记勾选帮助你的答案。
<input type='submit' name='Submit' id='SubmitRegister' value=''>
<input type='submit' name='Submit' id='SubmitRegister' value='Submit'>