-2

The problem is that i get this error in every code as a result of the input. I Created wit XAMPP a database and imported the table sheets with this code:

CREATE table clients(
name                    char(20)not null,
surname              char(20)not null,
birthplace   char(20)not null,
code           smallint primary key,
Unique(code)
);

INSERT INTO clients (code, name,surname,birthplace)
VALUES(49,"Francesco","Fabiano","Firenze"),
              ( 15,"Andrea","Colombo","Catania"),
              ( 79,"Elena","Battaglia","Napoli"),
              ( 25,"Sara","Grazie","Milano");

This as following is the php file:

<!DOCTYPE html>
<html>
<head>
<title>Data manipulation</title>
</head>
<body>
<form method="post" action="?php echo $_SERVER['PHP_SELF'];?">
<h1> Data to be modified </h1>
<p> Number of old customers </p> <input type="text" name="Nclients">
<p> Number of new customers </p> <input type="text" name="Nclients2">
<input type="submit" name="button" value="SUBMIT">
</form>
<?php
      include_once('mysql-fix.php');
    $host="localhost";
    $username="root";
    $password="";
    $db_nome="agency";
    $tab_nome="clients";
    mysql_connect($host, $username, $password) or die ('Unable to connect to server: ' . mysql_error());
    mysql_select_db($db_name) or die ('Database login failed: ' . mysql_error());
if(isset($_POST["button"]))
{
$Nclients2=$_POST["Nclients2"];
$Nclients=$_POST["Nclients"];
$sql= "UPDATE clienti";
$sql .= "SET Nclients = $Nclients2";
$sql .= "WHERE Nclients = $Nclients";
if (mysql_query($sql))
{
$righe = mysql_affected_rows();
echo "Data updated successfully";
}
else
{
echo "Error inserting" . mysql_error();
}
}
?>
</body>
</html>

for some reasonn the result i get is the following:

Uncaught mysqli_sql_exception: Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\mysql-fix.php:33 Stack trace: #0 C:\xampp\htdocs\mysql-fix.php(33): mysqli_connect('localhost', 'root', Object(SensitiveParameterValue)) #1 C:\xampp\htdocs\modifica.php(20): mysql_connect('localhost', 'root', 'root') #2 {main} thrown in C:\xampp\htdocs\mysql-fix.php on line 33

Dharman
  • 30,962
  • 25
  • 85
  • 135
TitanFrex
  • 11
  • 2
  • @Justinas this article is reffering to linux system, the problem its with widows i think, i will try – TitanFrex Apr 13 '23 at 21:42
  • 1
    **Warning:** `mysql_*` extension is deprecated as of PHP 5.5.0 (2013), and has been removed as of PHP 7.0.0 (2015). Instead, either the [mysqli](https://www.php.net/manual/en/book.mysqli.php) or [PDO_MySQL](https://www.php.net/manual/en/book.pdo.php) extension should be used. See also the [MySQL API Overview](https://www.php.net/manual/en/mysqlinfo.api.choosing.php) for further help while choosing a MySQL API. – Dharman Apr 13 '23 at 21:47
  • @TitanFrex the OS you're using is irrelevant to the problem of not knowing your mysql root password. And you shouldn't be using `root` for your web app anyway...that's the admin user. Instead, create a mysql user specifically for the app, with only the permissions it actually needs. And do this even for your local dev environment, so it mirrors your live environment and you don't get any nasty permissions surprises when you go live. – ADyson Apr 13 '23 at 23:42

1 Answers1

-2

Verify the MySQL credentials you are using

snk
  • 1