看似没有发布到PHP的HTML表单 [英] HTML Form seemingly not posting to PHP

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

问题描述

您好,感谢您的宝贵时间。



无论研究的数量如何,我都找不到已经讨论过的解决方案。

问题是提交按钮自动重定向,看起来没有发布表单。它一直工作,直到我从MySQL函数转换为MySQLi。其他所有功能都在工作,但这部分网站。


$ b HTML表单(myaccount.inc.php):

 < div id =change-password> 

< form class =clearfixaction =method =post>

< div>< span class =he1>更改密码< / span>< / div>

< div>
<?php include_once'controllers / accountController.php'; ?>
< / div>

< div>< label class =fieldlabelfor =password>当前密码:< / label>< / div>
< input type =passwordname =passwordid =passwordsize =23/>< br />

< div>< label class =fieldlabelfor =passwordnew1>新密码:< / label>< / div>
< input type =passwordname =passwordnew1id =passwordnew1size =23/>< br />

< div>< label class =fieldlabelfor =passwordnew2>确认新密码:< / label>< / div>
< input type =passwordname =passwordnew2id =passwordnew2size =23/>< br />

< input type =submitname =submitvalue =更改密码class =bt_changepass/>

< / form>

< / div>

然后,这个表单由于没有更好的术语,被一些PHP控制。


$ b

PHP(accountController.php):

  / /检查密码更改表单是否已提交。 
if(isset($ _ POST ['submit'])=='Change Password')
{
echo< br />;

//从数据库中获取数据。
$ sql = $ mysqli-> query(SELECT * FROM ss_members WHERE usr ='。$ _ SESSION ['usr']。'AND pass ='.md5($ _ POST ['password']] ) ')。
$ row = $ sql-> fetch_assoc();

//将持有我们的错误
$ err = array();

if($ _ POST ['password'] ==|| $ _POST ['passwordnew1'] ==|| $ _POST ['passwordnew2'] ==)
{
$ err [] ='所有字段必须填写!';

$ b $ if(!$ row ['pass'] == md5($ _ POST ['password'])&& $ _POST ['passwordnew1']!= && $ _POST ['passwordnew2']!=)
{
$ err [] ='当前密码不正确!

$ b $ if if($ _ POST ['passwordnew1']<> $ _POST ['passwordnew2'])
{
$ err [] ='New密码不匹配!';

$ b $ if if(!count($ err))
{
if($ row ['usr'])
{
//如果一切正常,请更改密码。
$ stmt = $ mysqli-> prepare(UPDATE ss_members SET pass = md5(?)WHERE usr = {$ _SESSION ['usr']});
$ stmt-> bind_param('s',$ _POST ['passwordnew1']);
$ stmt-> execute();
$ stmt-> close();

echo密码已经成功更新!< br />;
}
else
{
$ err [] ='有东西坏了!';


$ b $ if($ err)
{
//保存会话中的错误信息。
foreach($ err as $ error)
{
echo $ error。 < br />;
}
}

echo< br />;


解决方案



<?php include_once'controllers / accountController.php'; ?>



发送了标头之后。

移动

<?php include_once'controllers / accountController.php'; ?>



到页面顶部,在处理程序部分内,或者您可以将表单提交到



controllers / accountController.php



使用

< form class =clearfixaction =controllers / accountController.phpmethod =post>


Hello and thank you for your time.

Regardless of the amount of research I do, I cannot find an already-discussed solution to this problem.

The problem is that the submit button automatically redirects, seemingly without posting the form. It worked until I converted from MySQL functions to MySQLi. Everything else is working but this part of the website.

HTML form (myaccount.inc.php):

<div id="change-password">

<form class="clearfix" action="" method="post">

        <div><span class="he1">Change Password</span></div>

        <div>
            <?php include_once 'controllers/accountController.php'; ?>
        </div>

        <div><label class="fieldlabel" for="password">Current Password:</label></div>
        <input type="password" name="password" id="password" size="23" /><br />

        <div><label class="fieldlabel" for="passwordnew1">New Password:</label></div>
        <input type="password" name="passwordnew1" id="passwordnew1" size="23" /><br />

        <div><label class="fieldlabel" for="passwordnew2">Confirm New Password:</label></div>
        <input type="password" name="passwordnew2" id="passwordnew2" size="23" /><br />

        <input type="submit" name="submit" value="Change Password" class="bt_changepass" />

</form>

</div>

This form is then, for lack of a better term, controlled by some PHP.

PHP (accountController.php):

// Checking whether the Password Change form has been submitted.
if(isset($_POST['submit'])=='Change Password')
{
echo "<br />";

// Get the data from the database.
$sql = $mysqli->query("SELECT * FROM ss_members WHERE usr = '".$_SESSION['usr']."' AND pass = '".md5($_POST['password'])."'");
$row = $sql->fetch_assoc();

// Will hold our errors
$err = array();

if($_POST['password'] == "" || $_POST['passwordnew1'] == "" || $_POST['passwordnew2'] == "")
{
    $err[] = 'All the fields must be filled in!';
}

if(!$row['pass'] == md5($_POST['password']) && $_POST['passwordnew1'] != "" && $_POST['passwordnew2'] != "")
{
    $err[] = 'Current password is not correct!';
}

if($_POST['passwordnew1'] <> $_POST['passwordnew2'])
{
    $err[] = 'New passwords do not match!';
}

if(!count($err))
{
    if($row['usr'])
    {
        // If everything is OK change password.
        $stmt = $mysqli->prepare("UPDATE ss_members SET pass = md5(?) WHERE usr = {$_SESSION['usr']}");
        $stmt->bind_param('s', $_POST['passwordnew1']);
        $stmt->execute();
        $stmt->close();

        echo "Password has been sucessfully updated!<br />";
    }
    else
    {
        $err[]='Something broke!';
    }
}

if($err)
{
    // Save the error messages in the session.
    foreach($err as $error)
    {
        echo $error . "<br />";
    }   
}

echo "<br />";
}

解决方案

The problem is you are including the

<?php include_once 'controllers/accountController.php'; ?>

after the headers have been sent.

You can either move the

<?php include_once 'controllers/accountController.php'; ?>

to the top of the page, inside the handler part, or you can submit the form to

controllers/accountController.php

using

<form class="clearfix" action="controllers/accountController.php" method="post">

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

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