function handleRegister() { //showLog("handleLogin"); // $ret = array('op' => 'register', 'msg' => 'Registration Successful', 'error_code' => '0'); $username = $_POST["username"]; $email = $_POST["email"]; $password = $_POST["password"]; $upass = md5(mysql_real_escape_string($_POST['password'])); $dao = new DAOuser(); // ensure that user with same email does not exist in database $user = $dao->getByEmail($email); // user already exists for give email if ($user != NULL) { $ret["error_code"] = "1"; $ret["msg"] = "Email '" . $email . "' already exists"; echo json_encode($ret); return; } // ensure that user with same username does not exist in database $user = $dao->getByUsername($username); // user already exists for give username if ($user != NULL) { $ret["error_code"] = "1"; $ret["msg"] = "Username '" . $username . "' already exists"; echo json_encode($ret); return; } $user = new user($_POST['username'], $upass, $_POST['email']); $dao->save($user); echo json_encode($ret); }
<?php include "db.php"; include "class.user.dao.php"; $dao = new DAOuser(); $vo = new user($_POST["username"], $_POST["password"], $_POST["email"]); if (isset($_POST["uid"])) { $vo->uid = $_POST["uid"]; } $dao->save($vo); header("Location: user.php");