not working insert to linux

Posted August 9, 2021 231 views

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


 $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);


                if (!$insert) {
                    $response = array(
                        'icon' => 'error',
                        'mensaje' => 'No fue posible guardar el nombre del rol.', 
                    $response = array(
                        'icon' => 'success',
                        'mensaje' => 'El usuario se creo correctamente.', 

    echo json_encode($response);
edited by KFSys

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.

Submit an Answer
2 answers
Show answer This answer has been marked as resolved by sistemasalianzamei.

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

mysql -u root -p votaciones_sas

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.

  • hello KFSys, I hope this is good thanks for answering, if I am inside the droplet create a virtual host with the name of, now if it is making the connection with the database, because the select, update if they work It is only the root user, verify and if you have the option to insert, I have done everything and I could not, that I can share you to help me :(