Send form to PHP

1

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.

<?php
$conexion=mysqli_connect("localhost","root","","bd_usuarios");
    $nombre=$_POST["nombre"];
    $contraseña=$_POST["contraseña"];
    $email=$_POST["email"];
    $comentario=$_POST["comentario"];
$insertar ="INSERT INTO prueba1(nombre, contraseña, email, comentario) VALUES ('$nombre','contraseña','$email','$comentario')";
$resultado= mysqli_query($conexion, $insertar);
if(!$resultado){
    echo"conexion fallida";
}else{
    echo"conexion excelente";
}
mysqli_close($conexion);
?>
    
asked by element 03.10.2018 в 01:46
source

2 answers

2

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
0

I enclose your answer, just change what you need.

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

if(!$resultado){
    echo"<div class='alert alert-warning alert-dismissable'>Error de Conexion!</div>";
}else{
    echo"<div class='alert alert-success alert-dismissable'>Conexion Exitosa!</div>";
}
mysqli_close($conexion);
?>
    
answered by 03.10.2018 в 03:56