如何修复我的 CRUD 在更新 PHP MSQL 中不起作用的问题

我尝试在 m 网站中实现 CRUD,但我能够创建、读取和删除。然而,在开发Update功能的过程中出现了问题。谁能帮我?我将提供下面的代码。如果登录者是管理员,则该代码用于更新用户信息。谢谢。


<?php

// Include config file

require_once "config.php";


// Define variables and initialize with empty values

$firstname = $lastname = $email = $address = $status = $level = "";

$firstname_err = $lastname_err = $email_err = $address_err = $level_err = $status_err = "";


// Processing form data when form is submitted

if(isset($_POST["id"])){

    // Get hidden input value

    $id = $_POST["id"];


    // Validate name-first

    $input_firstname = trim($_POST["firstname"]);

    if(empty($input_firstname)){

        $firstname_err = "Please enter a first name.";

    } elseif(!filter_var($input_firstname, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\s]+$/")))){

        $firstname_err = "Please enter a valid first name.";

    } else{

        $firstname = $input_firstname;

    }


    //Validate lastname

    $input_lastname = trim($_POST["lastname"]);

    if(empty($input_lastname)){

        $lastname_err = "Please enter a last name.";

    } elseif(!filter_var($input_lastname, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\s]+$/")))){

        $lastname_err = "Please enter a valid last name.";

    } else{

        $lastname = $input_firstname;

    }


    //Validate email address

    $input_email = trim($_POST["email"]);

    if(empty($input_email)){

        $email_err = "Please enter an email address.";

    } else{

        $email = $input_email;

    }


    // Validate address 

    $input_address = trim($_POST["address"]);

    if(empty($input_address)){

        $address_err = "Please enter an address.";

    } else{

        $address = $input_address;

    }


临摹微笑
浏览 134回答 3
3回答

潇潇雨雨

<?php// Include config filerequire_once "config.php";// Define variables and initialize with empty values$firstname = $lastname = $email = $address = $status = $level = "";$firstname_err = $lastname_err = $email_err = $address_err = $level_err = $status_err = "";// Processing form data when form is submittedif(isset($_POST["id"])){&nbsp; &nbsp; // Get hidden input value&nbsp; &nbsp; $id = $_POST["id"];&nbsp; &nbsp; // Validate name-first&nbsp; &nbsp; $input_firstname = trim($_POST["firstname"]);&nbsp; &nbsp; if(empty($input_firstname)){&nbsp; &nbsp; &nbsp; &nbsp; $firstname_err = "Please enter a first name.";&nbsp; &nbsp; } elseif(!filter_var($input_firstname, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\s]+$/")))){&nbsp; &nbsp; &nbsp; &nbsp; $firstname_err = "Please enter a valid first name.";&nbsp; &nbsp; } else{&nbsp; &nbsp; &nbsp; &nbsp; $firstname = $input_firstname;&nbsp; &nbsp; }&nbsp; &nbsp; //Validate lastname&nbsp; &nbsp; $input_lastname = trim($_POST["lastname"]);&nbsp; &nbsp; if(empty($input_lastname)){&nbsp; &nbsp; &nbsp; &nbsp; $lastname_err = "Please enter a last name.";&nbsp; &nbsp; } elseif(!filter_var($input_lastname, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\s]+$/")))){&nbsp; &nbsp; &nbsp; &nbsp; $lastname_err = "Please enter a valid last name.";&nbsp; &nbsp; } else{&nbsp; &nbsp; &nbsp; &nbsp; $lastname = $input_firstname;&nbsp; &nbsp; }&nbsp; &nbsp; //Validate email address&nbsp; &nbsp; $input_email = trim($_POST["email"]);&nbsp; &nbsp; if(empty($input_email)){&nbsp; &nbsp; &nbsp; &nbsp; $email_err = "Please enter an email address.";&nbsp; &nbsp; } else{&nbsp; &nbsp; &nbsp; &nbsp; $email = $input_email;&nbsp; &nbsp; }&nbsp; &nbsp; // Validate address&nbsp;&nbsp; &nbsp; $input_address = trim($_POST["address"]);&nbsp; &nbsp; if(empty($input_address)){&nbsp; &nbsp; &nbsp; &nbsp; $address_err = "Please enter an address.";&nbsp; &nbsp; } else{&nbsp; &nbsp; &nbsp; &nbsp; $address = $input_address;&nbsp; &nbsp; }&nbsp; &nbsp; // Validate access level&nbsp; &nbsp; $input_level = trim($_POST["level"]);&nbsp; &nbsp; if(empty($input_level)){&nbsp; &nbsp; &nbsp; &nbsp; $level_err = "Please enter an level.";&nbsp; &nbsp; } elseif($input_level == 'Admin'){&nbsp; &nbsp; &nbsp; &nbsp; $level = $input_level;&nbsp; &nbsp; }elseif($input_level == 'Customer'){&nbsp; &nbsp; &nbsp; &nbsp; $level = $input_level;&nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; $level_err = 'Please choose from Admin or Customer';&nbsp; &nbsp; }&nbsp; &nbsp; // Validate status&nbsp; &nbsp; $input_status = trim($_POST["status"]);&nbsp; &nbsp; if(empty($input_status)){&nbsp; &nbsp; &nbsp; &nbsp; $status_err = "Please enter a status";&nbsp; &nbsp; }elseif($input_status == '1'){&nbsp; &nbsp; &nbsp; &nbsp; $status = $input_status;&nbsp; &nbsp; }elseif($input_status == '0'){&nbsp; &nbsp; &nbsp; &nbsp; $status = $input_status;&nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; $status_err = "Please enter a valid status";&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; echo "<script>alert('";&nbsp; &nbsp; echo "Checking all inputs vales---";&nbsp;&nbsp; &nbsp; echo $id; echo "=id--<br>";&nbsp; &nbsp; echo $input_firstname; echo "=fname---<br>";&nbsp; &nbsp; echo $input_lastname; echo "=lname---<br>";&nbsp; &nbsp; echo $input_email; echo "=email---<br>";&nbsp; &nbsp; echo $input_address; echo "=add---<br>";&nbsp; &nbsp; echo $input_level; echo "=level<br>";&nbsp; &nbsp; echo $input_status; echo "=stat<br>";&nbsp; &nbsp; echo "')</script> ";&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; // Check input errors before inserting in database&nbsp; &nbsp; if(empty($firstname_err) && empty($lastname_err) && empty($email_err) && empty($address_err) && empty($level_err) && empty($status_err)){&nbsp; &nbsp; &nbsp; &nbsp; // Prepare an update statement&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "<script>alert('";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "Im inside `Check Inputs before inserting in database` If Block... All Good so far"; echo "<br>";&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "')</script> ";&nbsp; &nbsp; &nbsp; &nbsp; $sql = "UPDATE users SET firstname=?, lastname=? address=?, email=?, access_level=?, status=? WHERE id=?";&nbsp; &nbsp; &nbsp; &nbsp; if($stmt = mysqli_prepare($link, $sql)){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "<script>alert('";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "Im inside `mysqli_prepare` If Block... All Good so far"; echo "<br>";&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "')</script> ";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Bind variables to the prepared statement as parameters&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mysqli_stmt_bind_param($stmt, "sssssii", $param_firstname, $param_lastname, $param_address, $param_email, $param_level, $param_status, $param_id);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set parameters&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $param_firstname = $firstname;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $param_lastname = $lastname;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $param_address = $address;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $param_email = $email;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $param_level = $level;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $param_status = $status;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $param_id = $id;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Attempt to execute the prepared statement&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(mysqli_stmt_execute($stmt)){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Records updated successfully. Redirect to landing page&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "<script>alert('";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "Im inside `mysqli_stmt_execute` If Block... All Good so far"; echo "<br>";&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "')</script> ";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; header("location: index.php");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "<script>alert('";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "Im inside `mysqli_stmt_execute` If Block... Not Good"; echo "<br>";&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "')</script> ";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "Something went wrong. Please try again later.";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Close statement&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mysqli_stmt_close($stmt);&nbsp; &nbsp; &nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "<script>alert('";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "Im directly into else block from `empty input check If` Block... Not Good"; echo "<br>";&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "')</script> ";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo mysqli_stmt_error($stmt);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; // Close connection&nbsp; &nbsp; mysqli_close($link);} else{&nbsp; &nbsp; // Check existence of id parameter before processing further&nbsp; &nbsp; if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){&nbsp; &nbsp; &nbsp; &nbsp; // Get URL parameter&nbsp; &nbsp; &nbsp; &nbsp; $id =&nbsp; trim($_GET["id"]);&nbsp; &nbsp; &nbsp; &nbsp; // Prepare a select statement&nbsp; &nbsp; &nbsp; &nbsp; $sql = "SELECT * FROM users WHERE id = ?";&nbsp; &nbsp; &nbsp; &nbsp; if($stmt = mysqli_prepare($link, $sql)){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Bind variables to the prepared statement as parameters&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mysqli_stmt_bind_param($stmt, "i", $param_id);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set parameters&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $param_id = $id;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Attempt to execute the prepared statement&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(mysqli_stmt_execute($stmt)){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $result = mysqli_stmt_get_result($stmt);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(mysqli_num_rows($result) == 1){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* Fetch result row as an associative array. Since the result set contains only one row, we don't need to use while loop */&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $row = mysqli_fetch_array($result, MYSQLI_ASSOC);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Retrieve individual field value&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $firstname = $row["firstname"];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $lastname = $row["lastname"];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $email = $row["email"];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $address = $row["address"];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $level = $row["access_level"];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $status = $row["status"];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // URL doesn't contain valid id. Redirect to error page&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; header("location: error.php");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "Oops! Something went wrong. Please try again later.";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; // Close statement&nbsp; &nbsp; &nbsp; &nbsp; mysqli_stmt_close($stmt);&nbsp; &nbsp; &nbsp; &nbsp; // Close connection&nbsp; &nbsp; &nbsp; &nbsp; mysqli_close($link);&nbsp; &nbsp; }&nbsp; else{&nbsp; &nbsp; &nbsp; &nbsp; // URL doesn't contain id parameter. Redirect to error page&nbsp; &nbsp; &nbsp; &nbsp; header("location: error.php");&nbsp; &nbsp; &nbsp; &nbsp; exit();&nbsp; &nbsp; }}?><?php// core configurationinclude_once "../../config/core.php";// check if logged in as admininclude_once "../login_checker.php";// set page title$page_title = "Update Record";// include page header HTMLinclude '../layout_head.php';echo "<div class='col-md-12'>";// get parameter values, and to prevent undefined index notice$action = isset($_GET['action']) ? $_GET['action'] : "";// tell the user he's already logged inif ($action == 'already_logged_in') {&nbsp; &nbsp; echo "<div class='alert alert-info'>";&nbsp; &nbsp; echo "<strong>You</strong> are already logged in.";&nbsp; &nbsp; echo "</div>";} else if ($action == 'logged_in_as_admin') {&nbsp; &nbsp; echo "<div class='alert alert-info'>";&nbsp; &nbsp; echo "<strong>You</strong> are logged in as admin.";&nbsp; &nbsp; echo "</div>";}echo "</div>";//content when logged in?><div class="wrapper" style="width: 500px; margin: 0 auto;">&nbsp; &nbsp; <div class="container-fluid">&nbsp; &nbsp; &nbsp; &nbsp; <div class="row">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="col-md-12">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="page-header">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h2>Update Record</h2>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p>Please edit the input values and submit to update the record.</p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <form action="<?php echo htmlspecialchars(basename($_SERVER['REQUEST_URI'])); ?>" method="post">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="form-group <?php echo (!empty($firstname_err)) ? 'has-error' : ''; ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label>First Name</label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="text" name="firstname" class="form-control" value="<?php echo $firstname; ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="help-block"><?php echo $firstname_err;?></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="form-group <?php echo (!empty($lastname_err)) ? 'has-error' : ''; ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label>Last Name</label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="text" name="lastname" class="form-control" value="<?php echo $lastname; ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="help-block"><?php echo $lastname_err;?></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="form-group <?php echo (!empty($address_err)) ? 'has-error' : ''; ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label>Email</label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="email" name="email" class="form-control" value="<?php echo $email; ?>" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="help-block"><?php echo $email_err;?></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="form-group <?php echo (!empty($address_err)) ? 'has-error' : ''; ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label>Address</label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <textarea name="address" class="form-control"><?php echo $address; ?></textarea>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="help-block"><?php echo $address_err;?></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="form-group <?php echo (!empty($level_err)) ? 'has-error' : ''; ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label>Access Level</label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="text" name="level" class="form-control" value="<?php echo $level; ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="help-block"><?php echo $level_err;?></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="form-group <?php echo (!empty($status_err)) ? 'has-error' : ''; ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label>Status</label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="text" name="status" class="form-control" value="<?php echo $status; ?>">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="help-block"><?php echo $status_err;?></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="hidden" name="id" value="<?php echo $id; ?>"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="submit" class="btn btn-primary" value="Submit">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="index.php" class="btn btn-default">Cancel</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </form>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </div></div></body></html>我更新了代码,请运行该代码。我无法猜测还有什么可能是错误的,但我已经在您的代码中添加了一些回显。请运行一下看看哪里出错了。仔细检查您的bind_parameter类型。它们必须与您的数据库表类型完全相同。我只是帮助你给你一个例子而不是整个解决方案。现在您可以看到警报显示您在哪里,以便您可以追踪问题希望它能帮助并解决您的问题。

哔哔one

&nbsp; // paginationpublic class PaginationList<T> : List<T>&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; public PaginationList(List<T> values,int count , int page , int pageSize)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddRange(values);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TotalPage = (int)Math.Ceiling(count / (double)pageSize);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Page= page;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public int TotalPage { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; public int Page { get; set; }&nbsp; &nbsp; &nbsp; &nbsp; public bool HasPreviuos { get => Page > 1; }&nbsp; &nbsp; &nbsp; &nbsp; public bool HasNextiuos { get => Page < TotalPage; }&nbsp; &nbsp; &nbsp; &nbsp; public static PaginationList<T> Craete(IQueryable<T> query , int page , int pageSize)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return new PaginationList<T>(query.Skip((page - 1) * pageSize).Take(pageSize).ToList(), query.Count(), page, pageSize);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp;&nbsp;// javascript&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; let itemdelete = document.querySelectorAll(".item-delete");&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; itemdelete.forEach(btn => btn.addEventListener("click", function (e) {&nbsp; &nbsp; &nbsp; &nbsp; e.preventDefault();&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; Swal.fire({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title: 'Are you sure?',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text: "You won't be able to revert this!",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; icon: 'warning',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showCancelButton: true,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; confirmButtonColor: '#3085d6',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cancelButtonColor: '#d33',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; confirmButtonText: 'Yes, delete it!'&nbsp; &nbsp; &nbsp; &nbsp; }).then((result) => {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (result.isConfirmed) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let url = btn.getAttribute("href");&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fetch(url)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .then(response => {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (response.status == 200) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.location.reload(true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert("errorrr");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }))&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; //account&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; using Anyar.Models;&nbsp; &nbsp; using Anyar.ViewModels;&nbsp; &nbsp; using Microsoft.AspNetCore.Identity;&nbsp; &nbsp; using Microsoft.AspNetCore.Mvc;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; namespace Anyar.Controllers&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; public class AccountController : Controller&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; private readonly UserManager<AppUser> _userManager;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; private readonly RoleManager<IdentityRole> _roleManager;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; private readonly SignInManager<AppUser> _signInManager;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public AccountController(UserManager<AppUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<AppUser> signInManager)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _userManager = userManager;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _roleManager = roleManager;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _signInManager = signInManager;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public IActionResult Index()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public async Task<IActionResult> CreateAdmin()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AppUser user = new AppUser&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Fullname = "Kamil Qurbanov",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UserName = "SuperAdminKamil"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var result = await _userManager.CreateAsync(user, "Kamil000");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Ok(result);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public async Task<IActionResult> CreateRole()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IdentityRole role = new IdentityRole("SuperAdmin");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IdentityRole role2 = new IdentityRole("Admin");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IdentityRole role3 = new IdentityRole("Member");&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; await _roleManager.CreateAsync(role);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; await _roleManager.CreateAsync(role2);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; await _roleManager.CreateAsync(role3);&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Ok("added");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public async Task<IActionResult> AddRole()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AppUser user = await _userManager.FindByNameAsync("SuperAdminKamil");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; await _userManager.AddToRoleAsync(user, "SuperAdmin");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Ok("added");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public IActionResult Login()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [HttpPost]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public async Task<IActionResult> Login(LoginViewModel adminLogin)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!ModelState.IsValid) { return View(); }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AppUser appUser = await _userManager.FindByNameAsync(adminLogin.Username);&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (appUser == null)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ModelState.AddModelError("", "name or password is invalid");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var result = await _signInManager.PasswordSignInAsync(appUser, adminLogin.Password, false, false);&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!result.Succeeded)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ModelState.AddModelError("", "name or password is invalid");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return RedirectToAction("index","home");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public async Task<IActionResult> Logout()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (User.Identity.IsAuthenticated)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; await _signInManager.SignOutAsync();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return RedirectToAction("index", "home");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public IActionResult Register()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [HttpPost]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public async Task<IActionResult> Register(RegisterViewModel register)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!ModelState.IsValid) { return View(); }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AppUser user = await _userManager.FindByNameAsync(register.Username);&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (user != null)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ModelState.AddModelError("username", "bele nir user name sitifade olunub");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user = await _userManager.FindByEmailAsync(register.Email);&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (user != null)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ModelState.AddModelError("email", "bele nir user email sitifade olunub");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user = new AppUser&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UserName = register.Username,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Email = register.Email,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Fullname = register.Fullname,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var result = await _userManager.CreateAsync(user, register.Password);&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!result.Succeeded)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (var err in result.Errors)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ModelState.AddModelError("", err.Description);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var roleresult = await _userManager.AddToRoleAsync(user, "Member");&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!roleresult.Succeeded)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (var err in roleresult.Errors)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ModelState.AddModelError("", err.Description);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return RedirectToAction("login", "account");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }

慕村9548890

// javascript&nbsp; let itemdelete = document.querySelectorAll(".item-delete");itemdelete.forEach(btn => btn.addEventListener("click", function (e) {&nbsp; &nbsp; e.preventDefault();&nbsp; &nbsp; Swal.fire({&nbsp; &nbsp; &nbsp; &nbsp; title: 'Are you sure?',&nbsp; &nbsp; &nbsp; &nbsp; text: "You won't be able to revert this!",&nbsp; &nbsp; &nbsp; &nbsp; icon: 'warning',&nbsp; &nbsp; &nbsp; &nbsp; showCancelButton: true,&nbsp; &nbsp; &nbsp; &nbsp; confirmButtonColor: '#3085d6',&nbsp; &nbsp; &nbsp; &nbsp; cancelButtonColor: '#d33',&nbsp; &nbsp; &nbsp; &nbsp; confirmButtonText: 'Yes, delete it!'&nbsp; &nbsp; }).then((result) => {&nbsp; &nbsp; &nbsp; &nbsp; if (result.isConfirmed) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let url = btn.getAttribute("href");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fetch(url)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .then(response => {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (response.status == 200) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; window.location.reload(true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert("errorrr");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; })}))&nbsp;//account&nbsp;using Anyar.Models;using Anyar.ViewModels;using Microsoft.AspNetCore.Identity;using Microsoft.AspNetCore.Mvc;namespace Anyar.Controllers{&nbsp; &nbsp; public class AccountController : Controller&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; private readonly UserManager<AppUser> _userManager;&nbsp; &nbsp; &nbsp; &nbsp; private readonly RoleManager<IdentityRole> _roleManager;&nbsp; &nbsp; &nbsp; &nbsp; private readonly SignInManager<AppUser> _signInManager;&nbsp; &nbsp; &nbsp; &nbsp; public AccountController(UserManager<AppUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<AppUser> signInManager)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _userManager = userManager;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _roleManager = roleManager;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _signInManager = signInManager;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public IActionResult Index()&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public async Task<IActionResult> CreateAdmin()&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AppUser user = new AppUser&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Fullname = "Kamil Qurbanov",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UserName = "SuperAdminKamil"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var result = await _userManager.CreateAsync(user, "Kamil000");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Ok(result);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public async Task<IActionResult> CreateRole()&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IdentityRole role = new IdentityRole("SuperAdmin");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IdentityRole role2 = new IdentityRole("Admin");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IdentityRole role3 = new IdentityRole("Member");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; await _roleManager.CreateAsync(role);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; await _roleManager.CreateAsync(role2);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; await _roleManager.CreateAsync(role3);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Ok("added");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public async Task<IActionResult> AddRole()&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AppUser user = await _userManager.FindByNameAsync("SuperAdminKamil");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; await _userManager.AddToRoleAsync(user, "SuperAdmin");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Ok("added");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public IActionResult Login()&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; [HttpPost]&nbsp; &nbsp; &nbsp; &nbsp; public async Task<IActionResult> Login(LoginViewModel adminLogin)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!ModelState.IsValid) { return View(); }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AppUser appUser = await _userManager.FindByNameAsync(adminLogin.Username);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (appUser == null)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ModelState.AddModelError("", "name or password is invalid");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var result = await _signInManager.PasswordSignInAsync(appUser, adminLogin.Password, false, false);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!result.Succeeded)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ModelState.AddModelError("", "name or password is invalid");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return RedirectToAction("index","home");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public async Task<IActionResult> Logout()&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (User.Identity.IsAuthenticated)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; await _signInManager.SignOutAsync();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return RedirectToAction("index", "home");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public IActionResult Register()&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; [HttpPost]&nbsp; &nbsp; &nbsp; &nbsp; public async Task<IActionResult> Register(RegisterViewModel register)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!ModelState.IsValid) { return View(); }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AppUser user = await _userManager.FindByNameAsync(register.Username);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (user != null)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ModelState.AddModelError("username", "bele nir user name sitifade olunub");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user = await _userManager.FindByEmailAsync(register.Email);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (user != null)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ModelState.AddModelError("email", "bele nir user email sitifade olunub");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user = new AppUser&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UserName = register.Username,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Email = register.Email,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Fullname = register.Fullname,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var result = await _userManager.CreateAsync(user, register.Password);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!result.Succeeded)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (var err in result.Errors)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ModelState.AddModelError("", err.Description);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var roleresult = await _userManager.AddToRoleAsync(user, "Member");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!roleresult.Succeeded)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreach (var err in roleresult.Errors)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ModelState.AddModelError("", err.Description);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return View();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return RedirectToAction("login", "account");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP