Send form to PHP


Whenever I fill in the fields, and I run the code, I see "connection failed", and I do not understand. Can somebody help me? I'm new to php.

$insertar ="INSERT INTO prueba1(nombre, contraseña, email, comentario) VALUES ('$nombre','contraseña','$email','$comentario')";
$resultado= mysqli_query($conexion, $insertar);
    echo"conexion fallida";
    echo"conexion excelente";
asked by element 03.10.2018 в 01:46

2 answers


With the little information we have, I give you some suggestions:

1 - Verify that the name of your database is: bd_usuarios .

2 - Check if your username is "root" and you have not assigned a password.

3 - in this line you have lost the symbol $ in password: $insertar ="INSERT INTO prueba1(nombre, contraseña, email, comentario) VALUES ('$nombre','contraseña','$email','$comentario')"; (You also have special characters, change password by password .

PS: also verify that your table is called test1

answered by 03.10.2018 в 02:38

I enclose your answer, just change what you need.

    $conexion = new mysqli("localhost","root","","test"); // cabia tus datos
    $id = "1";
    $nombre="Test 1";// Solo necesitas cambiar tus variables
    //con las que necesites

    $resultado = mysqli_query($conexion, "INSERT INTO test(IDTest, Texto1) VALUES ('$id','$nombre')") 
        or die('error: '.mysqli_error($conexion));

    echo"<div class='alert alert-warning alert-dismissable'>Error de Conexion!</div>";
    echo"<div class='alert alert-success alert-dismissable'>Conexion Exitosa!</div>";
answered by 03.10.2018 в 03:56