所以我想在第一页上进行注册,即用户将在其中输入名称,姓氏等的用户信息,然后将其记录到数据库中并重定向到帐户信息页面用户输入用户名和密码并记录在另一个数据库中,因此我必须对学生表(存储所有信息)和用户表(存储帐户信息)进行记录,以便用户的userID将是学生,但是我不能将用户的ID号放在存储第一个页面的学生的表中,因此,如果我使用mysqli_insert_id,它可以将最后插入的用户的ID插入到学生表中,但是进入下一行而不是第一页中最后输入信息所在的行
第一页shs / functions / add.stud.php中的代码
<?php
session_start();
include 'database.php';
if (isset($_POST['add'])) {
echo "welcome";
}
$message = "Provide all information needed please";
$lname = $_POST['Lname'];
$fname = $_POST['Fname'];
$mname = $_POST['Mname'];
$email = $_POST['email'];
$grade = $_POST['grade'];
$strand = $_POST['strand'];
$section = $_POST['section'];
$status = $_POST['status'];
if (empty($lname) || empty($mname)) {
header("Location:../pages/user.add.php?empty=put something, will ya?");
exit();
}
else {
$sql = "INSERT INTO student (lname, fname, mname, gmail, grade, track, section, status)
VALUES ('$lname', '$fname', '$mname','$email', '$grade', '$strand', '$section', '$status')";
$result = mysqli_query($conn, $sql);
}
然后输入帐户信息(用户名,密码)
<?php
if (isset($_POST['users'])){
include_once 'database.php';
$uid = $_POST['uid'];
$pass = $_POST['pass'];
//pag check or pag handle sa mga errors sa pag log in
if (empty($uid) || empty($pass))
{
header("location:../pages/user.add.php?signup=empty fields");
exit();
} else {
$sql = "SELECT * FROM 'user' WHERE username ='$uid'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck < 0) {
header("Location:.../user.add.php?the inputs are already taken");
exit();
}
else {
$hashedpass = password_hash($pass, PASSWORD_DEFAULT);
//insert the new user to the user database
$sql = "INSERT INTO user (userID, username, password)
VALUES (NULL, '$uid', '$hashedpass');";
$result = mysqli_query($conn, $sql);
//pag connect sa student database
//katung sa database sa image
$sql = "SELECT * FROM user WHERE username ='$uid'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0){
while ($row = mysqli_fetch_assoc($result)){
$userid = $row['userID'];
$sql = "INSERT INTO profileimg (userID, status)
VALUES ('$userid', 1)";
if($result=mysqli_query($conn, $sql))
{
$last_id = mysqli_insert_id($conn);
$sql = "INSERT INTO student (userID) VALUES ('$last_id')";
$result = mysqli_query($conn, $sql);
}
else {
header("Location:.../user.add.php");
exit();
}
//pag add sa id sa user paingun sa student
header("Location:../pages/user.add.php");
}
}
将输入内容放置在第一页后,它将重定向到另一个页面,用户必须在该页面上输入帐户信息。这是所需功能
答案 0 :(得分:0)
最好的方法是将用户信息存储在student
表中,然后使用mysqli_insert_id
函数来获取studentId
。然后将帐户信息保存在user
表中,并抓住userId
。此后update
与student
的{{1}}表,其中userId
与您之前抓取的相同。
studentId