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