K
K
killsxs2020-04-15 18:14:50
PHP
killsxs, 2020-04-15 18:14:50

What are the errors in the code?

Notice: Undefined variable: id in D:\OSPanel\domains\localhost\3\reg\user.php on line 5

Notice: Undefined variable: username in D:\OSPanel\domains\localhost\3\reg\user.php on line 5

Notice: Undefined variable: email in D:\OSPanel\domains\localhost\3\reg\user.php on line 5

Notice: Undefined variable: password in D:\OSPanel\domains\localhost\3\reg\user.php on line 5

Notice: Undefined variable: ban in D:\OSPanel\domains\localhost\3\reg\user.php on line 5
Вот ошибки:

Notice: Undefined variable: role in D:\OSPanel\domains\localhost\3\reg\user.php on line 5

Warning: mysqli_connect(): (HY000/1045): Access denied for user ''@'localhost' (using password: NO) in D:\OSPanel\domains\localhost\3\reg\user.php on line 5

Fatal error: Uncaught Error: Call to undefined function myswli_query() in D:\OSPanel\domains\localhost\3\reg\user.php:6 Stack trace: #0 {main} thrown in D:\OSPanel\domains\localhost\3\reg\user.php on line 6


Here is the code:
<?php
    error_reporting(E_ALL);
    ini_set('display_errors','on');

    $link = mysqli_connect($id, $username, $email, $password, $ban, $role);
    myswli_query($link, "SET NAMES 'utf8'");

    if (isset($_GET['del'])){
        $id = $_GET['del'];

        $query = "DELETE FROM user WHERE id=$id";
        mysqli_query($link, $query) or die (mysqli_error($link));
    }

    $query = "SELECT * FROM user";
    $result = mysqli_query($link, $query) or die (mysqli_error($link));

    for ($data = []; $row = mysqli_fetch_assoc($result); $data[] = $row);

?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link rel="stylesheet" href="style.css">
    <title>Авторизация</title>
</head>
<body>

<table>
<?php foreach ($data as $user) { ?>
    <tr>
        <td><?= $user['id'] ?></td>
        <td><?= $user['username'] ?></td>
        <td><a href="?del=<?= $user['id'] ?>">delete</a></td>
    </tr>
<?php }?>
</table>

}

</body>
</html>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Matveev, 2020-04-15
@ematveev

myswli_query() replace with mysqli_query()

O
Oleg, 2020-04-15
@402d

First, variables are not taken out of thin air.
They must be determined prior to use.
Second
, $link = mysqli_connect($id, $username, $email, $password, $ban, $role);
read the description of this function.
Notice what it takes as parameters.
Connection parameters are usually placed in a separate . Also declare through constants.
Read about include, requiery and their include_once variants...
Having mastered the basic work with the database in a functional style, take a look at the ready-made wrapper classes.
Asset record approaches, doctrine, etc.
But first, all the same, the basics. then pdo and already abstractions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question