在这种情况下,我希望得到你的帮助。我是准备好的陈述的新手,并试图在数据库中插入一些信息,但我不能,我无法弄清楚出了什么问题。我已经尝试输出我需要的所有变量,并确保它们具有正确的值,所以,我需要你的帮助!
我的函数插入数据库。
function RegUser($mysqli, $fname, $lname, $username, $password, $email, $seccode){
if($stmt = $mysqli->prepare("INSERT INTO utilizadores (fname, lname, username, password, email, membership, userlevel, active, actcode, maxapps, maxlic, securitycode, uhash) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")){
$stmt->bind_param("sssssiiisiiis", $pnome, $unome, $user, $pass, $mail, $membro, $level, $ativo, $codigo, $maxapps, $maxlic, $scode, $hash);
// Dados obtidos do formulario
$pnome = $fname;
$unome = $lname;
$user = $username;
$pass = $password;
$mail = $email;
$scode = $seccode;
// dados obtidos de função
$membro = defMember($mysqli);
$level = defUserlevel($mysqli);
if(ReqAct($mysqli) == "1"){
$activo = "0";
}else{
$activo = "1";
}
$maxapps = GetMaxApps($mysqli, $membro);
$maxlic = GetMaxLics($mysqli, $membro);
$codigo = generate_actcode();
$hash = uHash();
if($stmt->execute()){
return true;
}else{
return false;
}
}
}
我的验证码:
if(isset($_POST['regbutton'])){
// verifica se os campos estão preenchidos
if(empty($_POST['fname'])){
$errors [] = 'PNOME';
}
if(empty($_POST['lname'])){
$errors [] = 'Preencher UNOME';
}
if(empty($_POST['byear'])){
$errors [] = 'BYEAR';
}
if(empty($_POST['username'])){
$errors [] = 'USERNAME';
}
if(empty($_POST['pass'])){
$errors [] = 'PASS';
}
if(empty($_POST['confpass'])){
$errors [] = 'CONF PASS';
}
if(empty($_POST['email'])){
$errors [] = 'EMAIL';
}
if(empty($_POST['confemail'])){
$errors [] = 'CONFEMAIL';
}
if(empty($_POST['cap'])){
$errors [] = 'CAP';
}
if(!isset($_POST['terms'])){
$errors [] = 'TERMS';
}
if((!empty($_POST['fname'])) AND (!empty($_POST['lname'])) AND (!empty($_POST['byear'])) AND (!empty($_POST['username'])) AND (!empty($_POST['pass'])) AND (!empty($_POST['confpass'])) AND (!empty($_POST['email'])) AND (!empty($_POST['confemail'])) AND (!empty($_POST['cap'])) AND (isset($_POST['terms']))){
$ok = false;
$fname = validar($link, $_POST['fname']);
$lname = validar($link, $_POST['lname']);
$byear = validar($link, $_POST['byear']);
$username = validar($link, $_POST['username']);
$pass = validar($link, $_POST['pass']);
$pass = md5($pass);
$confpass = validar($link, $_POST['confpass']);
$confpass = md5($confpass);
$email = validar($link, $_POST['email']);
$confemail = validar($link, $_POST['confemail']);
$cap = validar($link, $_POST['cap']);
if($cap != $_SESSION['CAPTCHA_CODE']){
$errors [] = 'Captcha Inválido';
}
if($pass != $confpass){
$errors [] = 'Passwords não conferem';
}
if($email != $confemail){
$errors [] = 'Emails não conferem';
}
if(strlen($byear) != "4"){
$errors [] = 'Ano de Nascimento tem de ter 4 digitos';
}
if(strlen($username) < "3" OR strlen($username) > "16"){
$errors [] = 'User deve ter entre 3 a 16 caracteres';
}
if(strlen($pass) < "8" OR strlen($pass) > "32" OR strlen($confpass) < "8" OR strlen($confpass) > "32"){
$errors [] = 'passwords entre 8 e 32';
}
if(RegCheckUser($link, $username) == true){
$errors [] = 'Username already at use';
}
if(RegCheckEmail($link, $email) == true){
$errors [] = 'Email already in use';
}
if(empty($errors)){
if(RegUser($link, $fname, $lname, $username, $pass, $email, $byear) == true){
$ok = true;
}else{
$errors [] = 'Error while creating account';
}
}
}
if($ok == True){ ?>
<div class="col-sm-12">
<!-- Danger Alert -->
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h3 class="push"><?php echo $lang['LOGIN_ERROROX']; ?></h3>
<ul>
</ul>
</div>
<!-- END Danger Alert -->
</div>
<?php
}
if(!empty($errors)){
?>
<div class="col-sm-12">
<!-- Danger Alert -->
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h3 class="push"><?php echo $lang['LOGIN_ERROROX']; ?></h3>
<ul>
<?php
foreach ($errors as $value){
echo "<li align='left'>".$value."</li>";
}
?>
</ul>
</div>
<!-- END Danger Alert -->
</div>
<?php
}
}
?>
在这种情况下有人可以帮助我吗?我只是无法弄清楚为什么每次都会出现同样的错误(打印的代码就是这个只是$ error []里面的信息:)
if(empty($errors)){
if(RegUser($link, $fname, $lname, $username, $pass, $email, $byear) == true){
$ok = true;
}else{
$errors [] = 'Error while creating account';
}
提前致谢。