[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Помогите с php кодом
dark123
Здравствуйте, у меня есть регистрация вот код
<?php
if(!defined("access")){die();}
Class Register{

//account email
private $email;
//account password
private $password;

//errors we will be showing to the user
private $error = '';
//which field have errors so they get a red border
private $error_fields = '';

/* Initializes the variables that we will be needing for the registration process
* $data Array - contains all user info of the form
*/

function __construct($data){
$misc = new Misc();
foreach ($data as $id => $val){
//assign each item to its variable
$this->$id = $misc->trimValue($val);//remove all spaces
}
}


/* Validates the user data
* all variables are initialized from the constructor above
* returns errors if found and registers user if not
*/

public function registerUser(){
$misc = new Misc(); //get the Misc Class

//are the variables blank? throw error

if (
$this->email != "" && $this->password != "")
{
//is the email address valid? if not throw an error
if(preg_match( "/^[\d\w\/+!=#|$?%{^&}*`'~-][\d\w\/\.+!=#|$?%{^&}*`'~-]*@[A-Z0-9][A-Z0-9.-]{1,61}[A-Z0-9]\.[A-Z]{2,6}$/ix", $this->email ) == 0){
$this->error .= '<li>Please enter a valid Email address.</li>';
$this->error_fields .= 'email';
}

//if the email already exist , throw an error... we dont need duplicates as well
if ($misc->emailExist(mysql_real_escape_string($this->email))){
$this->error .= '<li>This email is already taken.</li>';
$this->error_fields .= 'email';
}

//if password does not meet our criteria for the password (at least 6 characters length with maximum
//of 128 characters and alphanumeric throw an error

if (!ctype_alnum($this->password)
||
strlen($this->password)<6
|| strlen($this->password)>=128
|| !preg_match('`[A-Z]`',$this->password)
|| !
preg_match('`[a-z]`',$this->password)
|| !
preg_match('`[0-9]`',$this->password)
)
{
$this->error .= '<li>Your first password must have at least one of each: a-z A-Z 0-9 and be atleast 6 characters.</li>';
$this->error_fields .= 'password,';
}


//if no errors found , we are good... for now ;)
if ($this->error == ""){
//we gotta check if the passwords match
if ($this->password){
//and if the user has entered a valid gender... user can easily change the values from the HTML DOM

//make an array with all the data for the account

$array = array(

'email' => $misc->escapeValue($email),
'password' => $misc->escapeValue($this->password)


);


}
}
}
else{
//all fields are blank, tell the user to fill them.
$this->error .= '<li>Please fill in all fields.</li>';
//red marked fields
$this->error_fields .= 'email,password';
}

//no errors for sure(hopefully)
if ($this->error == ""){
//send user a message that the account is registered
$array = array(
'error' => false,
'message' => 'Successfully registered',
'inputs_errors' => ''
);
}else{
//else send the errors
$array = array(
'error' => true,
'message' => '<ul style="padding:0;margin:0;margin-left:15px;">'.$this->error.'</ul>',
'inputs_errors' => $this->error_fields
);
}
return $array;
}

/* @param $data Array - Contains users data
* Registers the users account
* returns nothing
*/

private function addUser($data){
$misc = new Misc();
//generate the users id
$user_id = $misc->generateId();
$flag = false;
//until flag is false
while ($flag == false){
//check if the user id exists
$q = mysql_query("SELECT * FROM users WHERE user_id='$user_id'") or die(mysql_error());
$rows = mysql_num_rows($q);
//if it does try again till you find an id that does not exist
if ($rows){
$user_id = $misc->generateId();
}else{
//if it does not exist, exit the loop
$flag = true;
}
}

if ($flag == true){
//md5 password
$password = md5($this->password);
if ($this->gender == 1){
$avatar = "photos/default_male.png";
}else{
$avatar = "photos/default_female.png";
}
//insert into db the data
mysql_query("INSERT INTO users VALUES ('', '$user_id', '$user_email', '$user_password')");
}
}

}

?>



А вот обработчик
<?php
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
define("access", true);
include_once 'config/config.php';
include_once 'classes/misc.class.php';
include_once 'classes/email.class.php';
include_once 'classes/photos.class.php';
$misc = new Misc();
$photos = new Photos();
//no errors at start
$error = false;
//message to return and inputs with errors
$message = $inputs_errors = $logged_in = $logged_out = '';
//assign all variables that we get via the ajax requests
$method = isset($_POST["method"]) ? $_POST["method"] : "";

$email = isset($_POST["email"]) ? $_POST["email"] : "";
$password = isset($_POST["password"]) ? $_POST["password"] : "";

$email = isset($_POST["email"]) ? $_POST["email"] : "";
$password = isset($_POST["password"]) ? $_POST["password"] : "";
$email_ue = isset($_POST["email_ue"]) ? $_POST["email_ue"] : "";
//send json back
$array = array(
'error' => $error,
'message' => $message,
'inputs_errors' => $inputs_errors
);
//if user is not logged in
if (!$misc->loggedIn()){
//signing in
if ($method == 'signin'){
//include the Login class
include_once 'classes/login.class.php';
$array = array(
'email' => $email,
'password' => $password
);
$login = new Login($array);
//log in the user
$recieve_data = $login->LoginUser();
//data got back from log in
$error = $recieve_data["error"];
$message = $recieve_data["message"];
$inputs_errors = $recieve_data["inputs_errors"];
$logged_in = $recieve_data["logged_in"];
//send json back
$array = array(
'error' => $error,
'message' => $message,
'inputs_errors' => $inputs_errors,
'logged_in' => $logged_in
);
}else if ($method == 'signup'){ //signing up
//includes the register class

include_once 'classes/register.class.php';
$array = array(
'email' => $email,
'password' => $password

);
$register = new Register($array);
//registers the user
$recieve_data = $register->registerUser();
//data got back from registration
$error = $recieve_data["error"];
$message = $recieve_data["message"];
$inputs_errors = $recieve_data["inputs_errors"];
//send json back
$array = array(
'error' => $error,
'message' => $message,
'inputs_errors' => $inputs_errors
);

}else if ($method == 'recover_password'){ //recover password
//include recover password library

include_once 'classes/recover_password.class.php';
$recover = new Recover_Password($email);
//send recover email to the user
$recieve_data = $recover->sendRecoverEmail();
//get back data from recover system
$error = $recieve_data["error"];
$message = $recieve_data["message"];
$inputs_errors = $recieve_data["inputs_errors"];
//send json back
$array = array(
'error' => $error,
'message' => $message,
'inputs_errors' => $inputs_errors
);
}else{
//every other method cannot go any further than getting an error.
$error = true;
$message = 'Could not complete the request.';
}
}
else{
//for logged in users
if ($method == 'update_settings'){
//updating user settings
//include the library

include_once 'classes/change_settings.class.php';
//send the array with the user data
$array = array(

'current_password' => $current_password,
'email' => $email,
'password' => $password
);
$cs = new ChangeSettings($array);
//update user Settings
$recieve_data = $cs->updateSettings();
$error = $recieve_data["error"];
$message = $recieve_data["message"];
$inputs_errors = $recieve_data["inputs_errors"];
//send json back
$array = array(
'error' => $error,
'message' => $message,
'inputs_errors' => $inputs_errors
);
}else
$message = 'Please log in to use these features.';//simple message when a user tries to do ajax requests when logged in and its not a logout or update settings method
}
if ($method == "admin_update_settings"){//changing user settings when logging in as admin
if (isset($_SESSION["logged_as_admin"])){
//updating user settings
//include the library

include_once 'classes/change_settings.class.php';
//send the array with the user data
$array = array(
'email' => $email,
'password' => $password
);
$cs = new ChangeSettings($array);
//update user Settings
$recieve_data = $cs->AdminUpdateSettings();
$error = $recieve_data["error"];
$message = $recieve_data["message"];
$inputs_errors = $recieve_data["inputs_errors"];
//send json back
$array = array(
'error' => $error,
'message' => $message,
'inputs_errors' => $inputs_errors
);
}
}

//headers for JSON
header('Content-type: application/json');
//encode the array that we sent back
echo json_encode($array);
}else die();
?>


Ввожу данные регистрация пишет прошла успешна POST 200 прошол а вот в mysql данные не приходят. Помогите
Если не по теме перенисите.
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.