Good day!

There is a code

<!DOCTYPE html> <html> <head> <?php $title = "Сайт гильдии"; require_once "blocks/head.php" ?> </head> <body> <?php require_once "blocks/header.php" ?> <div id="wrapper"> <div id="leftCol"> <div> <?php if (isset($_POST['nik']) && isset($_POST['class']) && isset($_POST['type']) && isset($_POST['part']) && isset($_POST['hole']) && isset($_POST['zatocka']) && isset($_POST['summ']) && isset($_POST['log']) && isset($_POST['pass'])) { $nik = $_POST['nik']; $class = $_POST['class']; $type = $_POST['type']; $part = $_POST['part']; $hole = $_POST['hole']; $zatocka = $_POST['zatocka']; $summ = $_POST['summ']; $log = $_POST['log']; $pass = $_POST['pass']; $con = mysqli_connect("127.0.0.1", "$log", "$pass", "rf", "3306"); mysqli_set_charset($con, "utf8"); if (mysqli_connect_errno()) { exit ("Вы ввели неправильный Логин и/или пароль"); echo "провал" . mysqli_connect_error(); } $query1 = "INSERT INTO `sklad` (nik, class, type, part, hole, zatocka, summ) VALUES ('$nik', '$class', '$type', '$part', '$hole', '$zatocka', '$summ');"; $result1 = mysqli_query($con, $query1); if ($result1 = 'true') { echo '<h3 style="color:#ff0000">Информация занесена в базу данных</h3>' . "<br>"; } else { echo "Информация не занесена в базу данных"; } $query = "SELECT * FROM sklad;"; //выбрать все записи из таблицы nickname $result = mysqli_query($con, $query); ... 

and the usual HTML form that the user fills out on the PHP page and which sends global variables to this code / file, including the last ones: the login and password to the MySQL database. If the user enters the correct data in advance, including the login / password, then there are no problems, everything is added to the database. But if the user has entered incorrect login and / or password, then errors from the top are displayed, like:

Warning: mysqli_connect (): (HY000 / 1044): Access denied for user '' @ 'localhost' to database 'rf' in C: \ wamp64 \ www \ site \ bd2.php on line 34

Warning: mysqli_set_charset () expects parameter 1 to be mysqli, boolean given in C: \ wamp64 \ www \ site \ bd2.php on line 35

The question is: how to remove these errors and leave only the phrase that immediately goes after these errors.

You entered an incorrect username and / or password

PS I'm new. Many technologies are not familiar to me.

  • What is the trick to trust the username / password mysql? Do you have access to mysql allowed only from localhost? :) - Visman
  • So far I can only realize the viewing of information in this way. Not enough skills for something more global. Access for a specific user will be read only. (Primitive authorization system) - Alexander Boldyrev
  • O_O bad idea - Suvitruf
  • tin of course. This has not even seen even once - Herrgott

1 answer 1

In general, I can answer your question like this.

I will add that you need to use the function of the pars configuration file.

parse_ini_file

In which you need to register the connection settings and much more. And create constants.

Then you need to connect to the base once using the Singeltone pattern. Well, then "buttons" Classes for adding something or for getting something from the base.

Warning: mysqli_set_charset () expects parameter 1 to be mysqli, boolean given in C: \ wamp64 \ www \ site \ bd2.php on line 35

Here you need to lead to the line all the data. Which should be like a string in the base, and clean them.

Well, at least that way))


$ name = htmlspecialchars (trim (strip_tags ($ _ POST ['name']))); $ name = (string) $ name;


Second, it seems to me that you need here like this.

 if (!$con) { die ("Вы ввели неправильный Логин и/или пароль".PHP_EOL."провал" . mysqli_connect_error().PHP_EOL); }else{ $query1 = "INSERT INTO `sklad` (nik, class, type, part, hole, zatocka, summ) VALUES ('$nik', '$class', '$type', '$part', '$hole', '$zatocka', '$summ');"; $result1 = mysqli_query($con, $query1);} 

http://php.net/manual/ru/function.mysqli-connect.php

  • Thanks, but another error appeared: Notice: Undefined variable: con in C: \ wamp64 \ www \ site \ bd2.php on line 34 - Alexander Boldyrev
  • you just need to declare the variable above like this $ con = "; - dpi
  • But in fact, if you are just learning, I would recommend that you make a slightly different connection to the database as? Write, I'll send you as a naked PHP to do it. - dpi
  • now connects with the correct username and password to the database. Okay, thanks for the help. Himself still digging. Apparently in the query branch where there is inaccuracy. - Alexander Boldyrev
  • one