Good afternoon, I have a small problem with my digital ocean server, when I upload my script to run it, the inserts from my site do not work, I have done everything but I don’t know what to do now, I show a screenshot of the small test code that have
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "PassowrdHere";
$db = "DBHere";
$con = new mysqli($dbhost, $dbuser, $dbpass,$db, 3306);
echo "<pre>";
echo $con->host_info . "\n";
echo $con->connect_errno . "\n";
/* $query = "INSERT INTO `empleados`(`cedula`) VALUES ('123')";
$insert = mysqli_query($con, $query);*/
$query = "INSERT INTO `empleados`(`cedula`) VALUES ('123')";
$insert = $con->query($query);
var_dump($insert);
if (!$insert) {
$response = array(
'icon' => 'error',
'mensaje' => 'No fue posible guardar el nombre del rol.',
);
}else{
$response = array(
'icon' => 'success',
'mensaje' => 'El usuario se creo correctamente.',
);
}
echo json_encode($response);
?>
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
It is already solved, it was that in the database table, all the information of the insert had to be inserted, it did not accept null values, so I have to put it to accept null values
Hi @sistemasalianzamei,
There are multiple reasons why you won’t be able to insert into or connect to a database at all. Your Database user might not have the proper permissions for your database, your DB password might be wrong, your script might not have the proper permissions, or you don’t have proper permissions to connect to MySQL outside of your Droplet.
In this case, you are using the user Root so the DB permission automatically is not applicable as the root user has access to everything.
What I’ll recommend you is to try and connect using the same credentials from CLI - command line interface. Basically, SSH to your Droplet and type in
Then enter your password and see if you were able to connect.
As I’m looking at your script, it seems you are connecting externally, not from inside the droplet, correct? If that’s the case, you may need to allow your IP Address on your Droplet on port 3306 to be able to connect.