HTML表格似乎没有发布到PHP
你好,感谢你的时间。HTML表格似乎没有发布到PHP
无论研究的数量如何,我都找不到已经讨论过的解决方案。
问题是,提交按钮自动重定向,看似没有张贴表单。它一直工作,直到我从MySQL函数转换为MySQLi。其他一切正在工作,但这部分的网站。
HTML表单(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>
这种形式的话,由于缺乏一个更好的词,被一些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 />";
}
问题是要包括的
<?php include_once 'controllers/accountController.php'; ?>
标题发送后。
您可以移动
<?php include_once 'controllers/accountController.php'; ?>
到页面的顶部,处理器部分的内部,也可以使用表单提交给
controllers/accountController.php
<form class="clearfix" action="controllers/accountController.php" method="post">
。在你的<form>
标签没有action
集,它是将数据发送到同一个文件。即,myaccount.inc.php
。
将其更改为:
<form class="clearfix" action="accountController.php" method="post">
试试这个:
给表单动作accountController.php
<form class="clearfix" action="accountController.php" method="post">
这不会解决或更改任何内容。 – 2013-03-01 05:59:40
@IvanIvković:解释为什么不呢? – 2013-03-01 06:02:28
因为空行为仍然将表单发送到当前查看页面。我认为accountController.php不是一个网页,它是一个脚本,是网页的一部分。 – 2013-03-01 06:55:25
将您的action
更改为此,因为accountController.php
存在于controllers
文件夹内。
<form class="clearfix" action="controllers/accountController.php" method="post">
mysqli的一类,而它的功能查询不是静态的,所以在那里,你必须声明的mysqli类的实例可以使用$mysqli->query
之前。
你应该把
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
前
$sql = $mysqli->query("SELECT * FROM ss_members WHERE usr = '".$_SESSION['usr']."' AND pass = '".md5($_POST['password'])."'");
$ mysqli是在另一个文件中定义的,它包含在父文件。 html表单和accountController都可以访问数据库,并通过mysql_ping()进行验证。 – 2013-03-01 06:36:49
你会得到什么错误? – 2013-03-01 07:02:26
而不是跟在页眉之后,它会直接重定向到索引。 – 2013-03-01 07:03:54
您的代码看起来也马车第一
是accountController.php一个网页或包含? – 2013-03-01 07:14:49