我有一个脚本,当用户输入我希望它添加到数据库总数中的代码时,我正在使用它,但是没有任何反应。
到目前为止,这是我的代码:
$err = array();
if (isset($_POST['doSubmit4']) === true ) // Was if ($_POST['access']=='submit')
{
$code = mysql_real_escape_string($_POST['access-key']); // Was $data['access-key']
$result = mysql_query("SELECT `akid`,`key`,`total_access` FROM access_keys WHERE id='$_SESSION[user_id]' AND type='1'") or die (mysql_error());
$num = mysql_num_rows($result);
// Match row found with more than 1 results - the key exists.
if ( $num > 0 ) {
list($akid,$key,$total_access) = mysql_fetch_row($result);
if ($code == $key) {
if(empty($err)){
$total_access++;
mysql_query("update access_keys set total_access='$total_access' where akid='$akid'") or die(mysql_error());
header("Location: ./");
}
} else {
$err[] = "Invalid Access Key. Please try again with correct access key.";
}
} else {
$err[] = "Error - Invalid Access Key. No access exists for your user ID.";
}
}
我希望它在每次用户输入正确的代码时添加到“总访问权限”字段,但它不起作用。
这是我的表单代码:
<form name="postAccess" id="postAccess" method="post" action="access.php">
<input type="password" name="access-key" id="access-key" style="background-color:black;color:white;" size="40" /><br/>
<input name="doSubmit4" type="submit" id="doSubmit4" value="submit">
</form>
最佳答案
如果是括号,它可能是你的 parent 。
尝试:
if (isset($_POST['access']) === true )
代替
if ( $_POST['access']=='submit' )
如果这似乎不起作用,请进行一些调试。
在 if 括号中抛出一些 echo 语句,以查看哪些条件为真,哪些不为真。
编辑:
我刚刚意识到另一个问题。
您的表单操作无效。这应该是您要将数据发布到的页面的路径。所以:
代替:
<form name="access" id="access" method="post" action="access">
你应该:
<form name="access" id="access" method="post" action="your-php-path-here.php">
注意如何 action
= "your-php-path-here.php"在上面的代码中。
关于php - 在 PHP 中添加到数据库中的字段总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11622415/