Я пытаюсь выучить mysqli.
я получаю эту ошибку:
Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::fetch_assoc() in C:\xampp\htdocs\bk2\login.php:14 Stack trace: #0 {main} thrown in C:\xampp\htdocs\bk2\login.php on line 14
а вот мой db-conn.php:
<?php
require('bk-config.php');
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($conn->connect_errno) {
echo "Failed to connect to MySQL: (" . $conn->connect_errno . ") " . $conn->connect_error;
}
вот мой логин.php:
<?php
include 'db-conn.php';
$post_username = $_POST['post_username'];
$post_password = $_POST['post_password'];
$sql = "SELECT username, password FROM users WHERE username = ? AND password = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ss", $post_username, $post_password);
$stmt->execute();
$rows = $stmt->num_rows;
if($rows = 1){
while ($row = $stmt->fetch_assoc()) {
echo $row['username'];
}
}
вот форма, которую я имею в index.php:
<form class="px-4 py-3" action="login.php" method="post">
<div class="form-group">
<label>Username:</label>
<input type="text" name="post_username" class="form-control" placeholder="Enter username">
<label class="mt-2">Password:</label>
<input type="password" name="post_password" class="form-control" placeholder="Password">
</div>
<button type="submit" class="btn btn-danger float-right">Login</button>
</form>
В чем проблема с fetch_assoc () в login.php?