I’m new at php and I got some problem that I don’t know how to fix, I made A HTML form that should change the name of a database
<div class="form-group">
<form action="name.php" method="post">
<input type="text" class="form-control" name="name">
<input type="submit" value="Submit" name="submit">
</form>
</div>
HTML form is also connected to PHP edit script
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "tbl_product";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql ="UPDATE tbl_product SET name='$name' WHERE id = ID LIMIT 1";
// Prepare statement
$stmt = $conn->prepare($sql);
// execute the query
$stmt->execute();
// echo a message to say the UPDATE succeeded
echo $stmt->rowCount() . " records UPDATED successfully";
header("Refresh:0; url=products.php");
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
?>
The script that I run won’t change the database name and if it changes it changes all database names. For now, looks like the script runs fine but nothing happened. I need to limit the changing data from database so one change does not change all.