簡體   English   中英

mysqli_fetch_assoc 不能與 mysqli_stmt_get_result 一起使用

[英]mysqli_fetch_assoc not working with mysqli_stmt_get_result

這是在我的網站上創建用戶的代碼...我的個人資料 img 需要一個 while 循環,所以我使用了此視頻代碼https://youtu.be/I4JYwRIjX6c的一部分但是當我去嘗試它時它給了我這個錯誤:

Fatal error: Uncaught TypeError: mysqli_fetch_assoc(): Argument #1 ($result) must be of type mysqli_result, bool given in C:\xampp\htdocs\WravyBike\Includes\functions.inc.php:152 Stack trace: #0 C :\xampp\htdocs\WravyBike\Includes\functions.inc.php(152): mysqli_fetch_assoc(false) #1 C:\xampp\htdocs\WravyBike\Includes\signup.inc.php(60): createUser(Object(mysqli ), 'test', 'test@gma...', '', 'test12') #2 {main} 拋出 C:\xampp\htdocs\WravyBike\Includes\functions.inc.php 上線 11

這是我的代碼:我遇到了問題:while ($row = mysqli_fetch_assoc($result)) & $result = mysqli_stmt_get_result($stmt);

    $sql = "INSERT INTO users (usersName, usersEmail, usersTel, usersPwd) VALUES (?, ?, ?, ?);";

// $sql = "INSERT INTO users (usersName, usersEmail, usersTel, usersPwd) VALUES ('$name', '$email', '$tel', '$pwd');";
$stmt = mysqli_stmt_init($conn);
// mysqli_query($conn, $sql);
if (!mysqli_stmt_prepare($stmt, $sql)) {
    header("location: ../signup.php?error=stmtfailed");
    exit();
}
else{
    $pwdHashed = password_hash($pwd, PASSWORD_DEFAULT);
    mysqli_stmt_bind_param($stmt, "ssss", $name, $email, $tel, $pwdHashed);
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);
    while ($row = mysqli_fetch_assoc($result)) {
        $userid = $row["usersId"];
        $sql = "INSERT INTO profileimg (usersId, status) VALUES ('$userid', 1);";
        $result = mysqli_query($conn, $sql);
        header("Location: ../EditAccount.php");
    }
    mysqli_stmt_close($stmt);
    header("location: ../signup.php?error=none");
    exit();
}
$result = mysqli_stmt_get_result($stmt);

在這部分,$result 將有一個 bool 值(true)如果它成功插入記錄(false)如果它失敗。

如果要更新此“profileimg”表中的用戶狀態,請使用此代碼

$last_id = $conn->insert_id;

mysqli_stmt_bind_param($stmt, "ssss", $name, $email, $tel, $pwdHashed);
if (mysqli_stmt_execute($stmt)) {
  $last_id = $conn->insert_id;
  $sql = "INSERT INTO profileimg (usersId, status) VALUES ('$last_id', 1);";
  $result = mysqli_query($conn, $sql);
  header("Location: ../EditAccount.php");
}

``

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM