0
I’m making a website, while testing locally this connection code worked
<?php
$servername = "localhost";
$database = "bdcomentarios";
$username = "root";
$password = "";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$nome = $_POST['nome'];
$email = $_POST['email'];
$comentario = $_POST['comentario'];
$data = date("Y/m/d");
if(strlen($_POST['nome'])) #insere somente se no form foi escrito o nome
{
$sql = "INSERT INTO tbcomentarios9 (nome, email, data, comentario) VALUES ('$nome', '$email', '$data', '$comentario') ORDER BY id DESC";
if (mysqli_query($conn, $sql)) {
header('Location: obrigado2.html');
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
?>
after uploading it to Cpanel, it stopped working and gave the error, "Warning: mysqli_connect(): (28000/1045): Access denied for user 'root'@'localhost'", I already tried to create a user with all permissions and uses, already checked the syntax, and nothing, someone can tell me what’s wrong?
means that the table order will be defined by the most recent "id" number (a column of my table)
– Raquel Teixeira
Where did you conclude "means that the order of the table will be defined by the number of "id""? If you want some order while recovering database data then use ORDER BY in SELECT. See the documentation that will make sure that there is no ORDER BY clause in INSERT.
– anonimo