我希望用户在首次登录时在技能页面中设置技能,就像一次性设置一样,以及将来登录时,他们不再需要再次设置它进入主页,因为他们已经设置了它,如果他们想要在他们的个人资料页面中更新它。 我怎样才能实现这一目标?我应该使用哪些查询?
任何建议都会有所帮助。谢谢!
这是我尝试但未能实现的代码。
import threading
def main():
# Initialise thread object
flag = threading.Event()
for i in range(2):
if i == 0:
t1 = threading.Thread(target=t1_func, args=(flag,))
t1.start()
else:
t2 = threading.Thread(target=t2_func, args=(flag,))
t2.start()
def t1_func(flag):
for i in range(100000000):
if i == 100000000 - 1:
flag.set()
def t2_func(flag):
while not flag.is_set():
print('not flag yet')
print('GOT FLAG !')
if __name__ == '__main__':
main()
答案 0 :(得分:0)
试试这个:
我假设user_skill.user_id
和
job_seeker.user_id
具有主键外键关系。
if (count($errors) == 0) {
$password = md5($password);
$query = "SELECT * FROM job_seeker WHERE username = '$username' AND password = '$password'";
$results = mysqli_query($db, $query);
// Below, I am getting the user_id from the user table and adding it in the WHERE Clause (So, there will rows ONLY when given user has defined any skills of his/her )
$user = mysqli_fetch_assoc($results);
$userId = $user['user_id'];
$querx = "SELECT user_skill.user_id AS id_one, job_seeker.user_id
AS id_two
FROM user_skill
INNER JOIN job_seeker ON (user_skill.user_id = job_seeker.user_id)
WHERE user_skill.user_id = $userId";
$result = mysqli_query($db, $querx);
if (mysqli_num_rows($results) == 1) {
session_regenerate_id();
$user = mysqli_fetch_assoc($results);
$job = mysqli_fetch_assoc($result);
$_SESSION['SESS_USER_ID'] = $user['user_id'];
$_SESSION['SESS_USER_IDs'] = $job ['user_id'];
$_SESSION['SESS_USER_NAME'] = $user['username'];
$_SESSION['SESS_FIRST_NAME'] = $user['f_name'];
$_SESSION['SESS_LAST_NAME'] = $user['l_name'];
$_SESSION['SESS_USER_EMAIL'] = $user['email'];
$_SESSION['SESS_BIRTH_DATE'] = $user['birthdate'];
$_SESSION['SESS_USER_GENDER'] = $user['gender'];
$_SESSION['SESS_USER_CONTACT'] = $user['contact'];
$_SESSION['SESS_USER_ADDRESS'] = $user['address'];
$_SESSION['SESS_USER_NATIONALITY'] = $user['nationality'];
if(mysqli_num_rows($result) > 0) {
header('location: userhome.php');
// Now, you don't need the below IF code
// Since, the rows will be only be returned if that
// particular user's skills exists in the table.
/* while($fetch = mysqli_fetch_assoc($result)) {
if($fetch['id_one'] === $fetch['id_two']) {
header('location: userhome.php');
}
else {
header('location: userskill.php');
}
} */
}
else {
header('location: userskill.php');
}
session_write_close();
}
else {
array_push($errors, "Wrong username or password!");
}
}
}
答案 1 :(得分:-1)
已经解决了这个问题,未来可能对某人有所帮助。
// LOGIN - NO ERRORS
if (count($errors) == 0) {
$password = md5($password);
$query = "SELECT * FROM job_seeker WHERE username = '$username' AND password = '$password'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
session_regenerate_id();
$user = mysqli_fetch_assoc($results);
$job = mysqli_fetch_assoc($result);
$_SESSION['SESS_USER_ID'] = $user['user_id'];
$_SESSION['SESS_USER_IDs'] = $job ['user_id'];
$_SESSION['SESS_USER_NAME'] = $user['username'];
$_SESSION['SESS_FIRST_NAME'] = $user['f_name'];
$_SESSION['SESS_LAST_NAME'] = $user['l_name'];
$_SESSION['SESS_USER_EMAIL'] = $user['email'];
$_SESSION['SESS_BIRTH_DATE'] = $user['birthdate'];
$_SESSION['SESS_USER_GENDER'] = $user['gender'];
$_SESSION['SESS_USER_CONTACT'] = $user['contact'];
$_SESSION['SESS_USER_ADDRESS'] = $user['address'];
$_SESSION['SESS_USER_NATIONALITY'] = $user['nationality'];
$_SESSION['SESS_DATE_REGISTERED'] = $user['date_registered'];
$_SESSION['SESS_USER_IMG'] = $user['avatar'];
$_SESSION['SESS_USER_STAT'] = $user['status'];
$userId = $user['user_id'];
$jobId = $job['user_id'];
$query = "SELECT * FROM job_seeker";
$resultx = mysqli_query($db, $query);
$user = mysqli_fetch_assoc($resultx);
$userId = $user['user_id'];
$skills = "SELECT *
FROM job_seeker
INNER JOIN user_skill ON user_skill.user_id = job_seeker.user_id
WHERE user_skill.user_id = '" . $_SESSION['SESS_USER_ID'] . "'";
$results = mysqli_query($db, $skills);
if($results->num_rows) {
header('location: userhome.php');
}
else {
header('location: userskill.php');
}
session_write_close();
}