Do not insert data in my database from PHP

0

Do not insert the data I leave you photo of the structure of my table and the code for which you can help me thanks.

The code is as follows.

<?php  
$con = mysqli_connect("localhost","root","","ufree") or die("conexion exitosa!");
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Registro</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="css/style.css" />

    <!-- Materia Design Bootstrap-->
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <!-- Bootstrap core CSS -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet">
    <!-- Material Design Bootstrap -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.5.12/css/mdb.min.css" rel="stylesheet">
</head>
<body>
<?php require 'partials/header.php';?>
<div class="contenedor">
    <div class="row justify-content-center">
        <div class="col-md-4 principal"> 
            <h2>Registrate en UFREE</h2>
            <form action="#" method="POST">
                <div class="form-group">
                    <label for="usuario">Codigo del estudiante:</label>
                    <input type="number" class="form-control" id="codE" name="idE" require="true">
                </div>
                <div class="form-group">
                    <label for="nombre">Primer Nombre:</label>
                    <input type="text" class="form-control" id="nombreE" name="nombre" require="true">
                </div>
                <div class="form-group">
                    <label for="nombre2">Segundo Nombre:</label>
                    <input type="text" class="form-control" id="nombre2E" name="nombre2" require="false"> 
                </div>
                <div class="form-group">
                    <label for="apellido">Primer Apellido:</label>
                    <input type="text" class="form-control" id="apellidoE" name="apellido" require="true">
                </div>
                <div class="form-group">
                    <label for="apellido2">Segundo Apellido:</label>
                    <input type="text" class="form-control" id="apellido2E" name="apellido2" require="false"> 
                </div>
                <div class="form-group">
                    <label for="telefono">Telefono:</label>
                    <input type="text" class="form-control" id="tel" name="telefono" require="false"> 
                </div>
                <div class="form-group">
                    <label for="email">Correo:</label>
                    <input type="email" class="form-control" id="email" name="correo" require="false"> 
                </div>
                <div class="form-group">
                    <label for="contraseña">Contraseña:</label>
                    <input type="password" class="form-control" id="passw" name="contraseña" require="false"> 
                </div>
                <div class="form-group">
                <label for="foto">Sube tu foto:</label>
                <input id="foto" name="images[]" type="file" multiple=true class="file-loading">
                </div>  
                <br><input type="submit" class="btn btn-primary" value="Registrar" name="insert">
            </form>
        </div>
    </div>

</div>
<?php
    if(isset($_POST['insert'])){ 
        $identificacion = $_POST['idE'];
        $nombre = $_POST['nombre'];
        $nombre2 = $_POST['nombre2'];
        $apellido = $_POST['apellido'];
        $apellido2 = $_POST['apellido2'];
        $tel = $_POST['telefono'];
        $email = $_POST['correo'];
        $pass = $_POST['contraseña'];

        $insertar = "INSERT INTO estudiante (idE, nombre, nombre2, apellido, apellido2, telefono, correo, contraseña) VALUES ('$identificacion', '$nombre', '$nombre2', '$apellido', '$apellido2', '$tel', '$email', '$pass')";
        $ejecutar = mysqli_query($con, $insertar);
        if ($ejecutar) {
            echo "<h3>Insertado Correctamente</h3>";
        }
    
    }


?>



   <!--script bootstrap 4-->
<script src="js/main.js"></script>
<script type="text/javascript" src="js/registro.js"></script>
<!-- JQuery -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Bootstrap tooltips -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.4/umd/popper.min.js"></script>
<!-- Bootstrap core JavaScript -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.min.js"></script>
<!-- MDB core JavaScript -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.5.12/js/mdb.min.js"></script>

</body>

</html>
    
asked by Camilo Rodriguez 16.10.2018 в 07:42
source

1 answer

2

Your problem is because of the encoding, by default your connection to the database does not support the letter ñ .

I've tried it with MariaDB and the problem was that. If just before executing the query, you set the charset, your form will be inserted into the database.

$con->set_charset("utf8");

It is also very useful to include traces in your code to detect what is happening:

When you establish the connection to the database, it shows what is happening if there is an error:

if (!$con) {
    echo "Error: No se pudo conectar a MySQL." . PHP_EOL;
    echo "errno de depuración: " . mysqli_connect_errno() . PHP_EOL;
    exit;
}

And when you execute the query, check if everything went well.

 if ($ejecutar === false ) {
    printf("error: %s\n", mysqli_error($con));
 }

Greetings.

    
answered by 16.10.2018 в 09:40