Error inserting records in php

0

I try to store values in my bd with php5 but for some reason I get an error, here is the html and the php: HTML:

<!DOCTYPE html>
<html>
<head>
    <title>Registro.</title>
</head>
<body>
<form action="Registro.php" method="POST">
    Servidor:
    <select name="selServidor"> <!-- selServidor quiere decir seleccionar servidor-->
        <option value="USA">USA</option>
        <option value="Eur">Eur</option>
    </select><br>
    Nombre: <input type="text" name="txtNombre"><br>
    Clase:
    <select name="selClase">
        <option value="A">A</option>
        <option value="B">B</option>
        <option value="C">C</option>
        <option value="D">D</option>
    </select><br>
    Representantes:
    <input type="text" name="txtRepresentantes"><br>
    Descripción:<br>
    <input type="text" name="txtDescripcion"><br>
    Tipo:
    <select name="selTipo">
        <option value="Competitivo">Competitivo</option>
        <option value="Casual">Casual</option>
    </select><br>
    Contacto: <input type="text" name="txtContacto"><br>
    <input type="submit" value="Registrar" name="btnRegistrar">
</form>
</body>
</html>

PHP:

<!DOCTYPE html>
<html>
<head>
    <title>Paso</title>
</head>
<body>
<?php /*aquí se debe colocar los datos que se configuraron
durante la creación de la base de datos y la tabla
*/
    $server = "localhost";
    $usuario = "root";
    $contrasena = "";
    $bd = "LatinClub";//nombre de la base de datos

    $conexion = mysqli_connect($server, $usuario, $contrasena, $bd) or die("Error en la conexion");

    $servidor = $_POST['selServidor'];
    $nombre = $_POST['txtNombre'];
    $clase = $_POST['selClase'];
    $representantes = $_POST['txtRepresentantes'];
    $descripcion = $_POST['txtDescripcion'];
    $tipo = $_POST['selTipo'];
    $contacto = $_POST['txtContacto'];

    $insertar = "INSERT into datosPC values('$servidor', '$nombre', '$clase', '$representantes', '$descripcion', '$tipo', '$contacto')";

    $resultado = mysqli_query($conexion, $insertar) or die('Error al insertar los registros');

    mysqli_close($conexion);
    echo "¡Datos insertados!";
 ?>
</body>
</html>

The problem happens when instead of saying inserted data, it says error when inserting the records

    
asked by Daniel Ortin 01.01.2017 в 21:15
source

1 answer

1

An error that I see is that in your $insert you have not added your columns to evaluate.

  

Updated example:

$insertar = "INSERT into datosPC (servidor,nombre,clase,representantes,descripcion,tipo,contacto) VALUES ('$servidor', '$nombre', '$clase', '$representantes', '$descripcion', '$tipo', '$contacto')";

I have set servidor,nombre,clase,representantes,descripcion,tipo,contacto as an example, the name must match your columns in your table dataPC

    
answered by 01.01.2017 / 21:29
source