Tak jak w temacie.Utworzyłem sobie skrypt rejestracji(listing poniżej) o nazwie registration_action.php:
<?php
/*Include translating module,database settings,
functions needed to prepare data from form,
to insert them into database and user interface header.*/
include 'modules/translator.php';
include 'includes/database.php';
include 'includes/functions.php';
include 'includes/header.php';
/*Variables including data from registration.php form.*/
$name=$_POST['name'];
$surname=$_POST['surname'];
$nickname=$_POST['nickname'];
$email=$_POST['email'];
$password=$_POST['pass'];
$rpassword=$_POST['rpass'];
/*Variable used to count errors occured during registration process.*/
$errorcounter=0;
/*Variables used to display errors that occured during registration process.*/
$errornameset='';
$errorname='';
$errornamelength='';
$errorsurnameset='';
$errorsurname='';
$errorsurnamelength='';
$errornicknameset='';
$errornickname='';
$errornicknamelength='';
$erroremailset='';
$erroremail='';
$errorpasswordset='';
$errorpassword='';
$errorpasswordlength='';
$errorpasswordcomparison='';
$registrationset1='';
$registrationset2='';
$errordbconnection='';
if(empty($name)){
$errorcounter++;
$errornameset='•' . $LANG['ERR_REG_NAME_SET'] . '<br>';
}
elseif(!preg_match('/^[A-ZĄĆĘŁŃÓŚŹŻ][a-ząćęłńóśźż]{2,}$/', $name)){
$errorcounter++;
$errorname='•' . $LANG['ERR_REG_NAME_CHAR'] . '<br>';
}
elseif(strlen($name)<3 || strlen($name)>16){
$errorcounter++;
$errornamelength='•' . $LANG['ERR_REG_NAME_LENGTH'] . '<br>';
}
if(empty($surname)){
$errorcounter++;
$errorsurnameset='•' . $LANG['ERR_REG_SURNAME_SET'] . '<br>';
}
elseif(!preg_match('/^[A-ZĄĆĘŁŃÓŚŹŻ][a-ząćęłńóśźż]{2,}$/', $surname)){
$errorcounter++;
$errorsurname='•' . $LANG['ERR_REG_SURNAME_CHAR'] . '<br>';
}
elseif(strlen($surname)<3 || strlen($surname)>32){
$errorcounter++;
$errorsurnamelength='•' . $LANG['ERR_REG_SURNAME_LENGTH'] . '<br>';
}
if(empty($nickname)){
$errorcounter++;
$errornicknameset='•' . $LANG['ERR_REG_NICKNAME_SET'] . '<br>';
}
elseif(!preg_match('/^[A-Za-z0-9]{6,}$/', $nickname)){
$errorcounter++;
$errornickname='•' . $LANG['ERR_REG_NICKNAME_CHAR'] . '<br>';
}
elseif(strlen($nickname)<3 || strlen($nickname)>12){
$errorcounter++;
$errornicknamelength='•' . $LANG['ERR_REG_NICKNAME_LENGTH'] . '<br>';
}
if(empty($email)){
$errorcounter++;
$erroremailset='•' . $LANG['ERR_REG_EMAIL_SET'] . '<br>';
}
elseif(!preg_match('/^[A-Za-z0-9\.\-\_]{2,}\@[A-Za-z0-9\.\-\_]+\.[a-z]{2,4}$/', $email)){
$errorcounter++;
$erroremail='•' . $LANG['ERR_REG_EMAIL_CHAR'] . '<br>';
}
if(empty($password) || empty($rpassword)){
$errorcounter++;
$errorpasswordset='•' . $LANG['ERR_REG_PASSWORD_SET'] . '<br>';
}
elseif(!preg_match('/^[A-Za-z0-9\.\-_@#]{6,}$/', $password)){
$errorcounter++;
$errorpassword='•' . $LANG['ERR_REG_PASSWORD_CHAR'] . '<br>';
}
elseif(strlen($password)<6 || strlen($password)>32){
$errorcounter++;
$errorpasswordlength='•' . $LANG['ERR_REG_PASSWORD_LENGTH'] . '<br>';
}
elseif($password !== $rpassword){
$errorcounter++;
$errorpasswordcomparison='•' . $LANG['ERR_REG_PASSWORD_COMPARISON'] . '<br>';
}
if($errorcounter==1){
echo '<div class="warning"><div class="wimg"><img src="theme/original/images/warning.png"/></div><div class="wheaderc"><span class="wheader">'. $LANG['ERR_REG_COUNT_MESSAGE'] . $errorcounter . $LANG['ERR_REG_COUNT_1'] . '</span></div><div class="wspacer"></div><div class="errors">' .
$errornameset .
$errorname .
$errornamelength .
$errorsurnameset .
$errorsurname .
$errorsurnamelength .
$errornicknameset .
$errornickname .
$errornicknamelength .
$erroremailset .
$erroremail .
$errorpasswordset .
$errorpassword .
$errorpasswordlength .
$errorpasswordcomparison .
'</div><div class="aspacer"></div><a href="registration.php" class="reglink">' . $LANG['REG_FIX'] . '</a></div>';
}
elseif($errorcounter>1 && $errorcounter<5){
echo '<div class="warning"><div class="wimg"><img src="theme/original/images/warning.png"/></div><div class="wheaderc"><span class="wheader">'. $LANG['ERR_REG_COUNT_MESSAGE'] . $errorcounter . $LANG['ERR_REG_COUNT_1_5'] . '</span></div><div class="wspacer"></div><div class="errors">' .
$errornameset .
$errorname .
$errornamelength .
$errorsurnameset .
$errorsurname .
$errorsurnamelength .
$errornicknameset .
$errornickname .
$errornicknamelength .
$erroremailset .
$erroremail .
$errorpasswordset .
$errorpassword .
$errorpasswordlength .
$errorpasswordcomparison .
'</div><div class="aspacer"></div><a href="registration.php" class="reglink">' . $LANG['REG_FIX'] . '</a></div>';
}
elseif($errorcounter>4){
echo '<div class="warning"><div class="wimg"><img src="theme/original/images/warning.png"/></div><div class="wheaderc"><span class="wheader">'. $LANG['ERR_REG_COUNT_MESSAGE'] . $errorcounter . $LANG['ERR_REG_COUNT_4'] . '</span></div><div class="wspacer"></div><div class="errors">' .
$errornameset .
$errorname .
$errornamelength .
$errorsurnameset .
$errorsurname .
$errorsurnamelength .
$errornicknameset .
$errornickname .
$errornicknamelength .
$erroremailset .
$erroremail .
$errorpasswordset .
$errorpassword .
$errorpasswordlength .
$errorpasswordcomparison .
'</div><div class="aspacer"></div><a href="registration.php" class="reglink">' . $LANG['REG_FIX'] . '</a></div>';
}
else{
$pname=formdata($name);
$psurname=formdata($surname);
$pnickname=formdata($nickname);
$pemail=formdata($email);
$ppassword=sha1($password);
$group=1;
$token=uniquetoken();
$connection=mysqli_connect(db_server,db_user,db_password,db_name);
$regquery= "INSERT INTO users (name, surname, nickname, e-mail, password, group, token) VALUES ('$pname', '$psurname', '$pnickname', '$pemail', '$ppassword', '$group', '$token')";
if(mysqli_query($connection, $regquery)){
echo '<div class="alert"><div class="wimg"><img src="theme/original/images/alert.png"/></div><div class="aheaderc"><span class="aheader">'. $LANG['REG_COMPLETED_HEADER'] .'</span></div><div class="wspacer"></div><div class="alertm">' .
$registrationset1=$LANG['REG_COMPLETED_MESSAGE_1'] . $email . "." . $registrationset2=$LANG['REG_COMPLETED_MESSAGE_2'] .
'</div><div class="aspacer"></div><a href="index.php" class="mainlink">' . $LANG['REG_MAIN'] . '</a></div>';
mysqli_close($connection);
}
else{
echo '<div class="warning"><div class="wimg"><img src="theme/original/images/warning.png"/></div><div class="wheaderc"><span class="wheader">'. $LANG['DB_ERR_HEADER'] . '</span></div><div class="wspacer"></div><div class="errors">' .
$errordbconnection = $LANG['DB_ERR_CONNECTION'] .
'</div><div class="dbspacer"></div><a href="registration.php" class="reglink">' . $LANG['REG_FIX'] . '</a></div>';
}
}
include 'includes/footer.php';
?>
A w pliku testowym zbudowałem prosty moduł sprawdzający czy prawidłowo próbuję łączyć się z bazą:
<?php
$link = mysqli_connect('serwer', 'uzytkownik', 'haslo', 'nazwa_bazy');
if (!$link) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>
W powyższym pliku mam komunikat Connected successfully. Co jest nie tak z moim skryptem registration_action.php?Oczywiście skrypt jest wywoływany po właściwym uzupełnieniu formularza na poprzedniej stronie.Dodam że dane mało że są sprawdzane, to specjalne znaki są konwertowane w htmlspecialchars(),dodatkowo stripslashes() i trim().Do połączenia z bazą zrobiłem tymczasową własną obsługę błędu w HTML(pokazuje się ładnie wystylizowany komunikat w CSS’ie).Sprawdzałem czy przypadkiem rekrody mimo to nie są dodawane do bazy ale nic nie ma.Może przyda się jeszcze informacja, iż jak w registration_action.php parametry funkcji mysqli_connect dam w pojedyncze cudzysłowy to mam komunikat 502 Bad Gateway.Proszę o pomoc bo może coś odwaliłem głupiego tylko jestem już tak tym zmęczony że tego nie widzę.