我只想在两个差异中插入相同的数据。表。例。我想用患者名,密码,fname,lname,年龄性别注册患者。并将此数据插入表PATIENT_USER中。我还想将用户名和密码插入表USERS。那可能吗?这是我的脚本PHP
<?php
class user_DB_Functions {
private $db;
//put your code here
// constructor
function __construct() {
require_once 'user_DB_Connect.php';
// connecting to database
$this->db = new user_DB_Connect();
$this->db->connect();
}
// destructor
function __destruct() {
}
/**
* Storing new user
* returns user details
*/
public function storeUser($username, $password, $fname, $lname, $gender, $address, $contact, $age, $birthday) {
$uuid = uniqid('', true);
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$result = mysql_query("INSERT INTO patient_user(unique_id, username, encrypted_password, fname, lname, gender, address,contact, age, birthday, salt, created_at) VALUES('$uuid', '$username', '$encrypted_password', '$fname', '$lname', '$gender','$address','$contact','$age','$birthday','$salt', NOW())");
$result1 = mysql_query("INSERT INTO users(unique_id, username, encrypted_password) VALUES('$uuid', '$username', '$encrypted_password')");
// check for successful store
if ($result) {
// get user details
$uid = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM patient_user WHERE uid = $uid");
// return user details
return mysql_fetch_array($result);
} else {
return false;
}
}
/**
* Get user by username and password
*/
public function getUserByusernameAndPassword($username, $password) {
$result = mysql_query("SELECT * FROM patient_user WHERE username = '$username'") or die(mysql_error());
// check for result
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
$result = mysql_fetch_array($result);
$salt = $result['salt'];
$encrypted_password = $result['encrypted_password'];
$hash = $this->checkhashSSHA($salt, $password);
// check for password equality
if ($encrypted_password == $hash) {
// user authentication details are correct
return $result;
}
} else {
// user not found
return false;
}
}
/**
* Check user is existed or not
*/
public function isUserExisted($username) {
$result = mysql_query("SELECT username from patient_user WHERE username = '$username'");
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
// user existed
return true;
} else {
// user not existed
return false;
}
}
/**
* Encrypting password
* @param password
* returns salt and encrypted password
*/
public function hashSSHA($password) {
$salt = sha1(rand());
$salt = substr($salt, 0, 10);
$encrypted = base64_encode(sha1($password . $salt, true) . $salt);
$hash = array("salt" => $salt, "encrypted" => $encrypted);
return $hash;
}
/**
* Decrypting password
* @param salt, password
* returns hash string
*/
public function checkhashSSHA($salt, $password) {
$hash = base64_encode(sha1($password . $salt, true) . $salt);
return $hash;
}
}
?>
请帮帮我。