INSERT INTO does not work and the code does not give an error

0

I try to insert data into the database, mysql and it does not give me the else error and no php error or something, 3 days ago I'm trying to find how to do it and nothing, the code is fine, but it throws the error and the database does not receive anything, and phpMyAdmin gives me error in the example INSERT of all the databases that I have, but the other bases with similar code work correctly and that of my base there is no way, I wanted to finish this project today, and it will not be able to be seems, this error left me out, it is more, I have in the same project the users section with the similar code and if you add users.

<?php 
require_once('conexion.php');
$nombre = $_POST['nombre'];
$productos = $_POST['productos'];
$telefono = $_POST['telefono'];
$email = $_POST['email'];
$query = "INSERT INTO proveedores (nombre,productos,telefono,email) values('$nombre','$productos','$telefono','$email')";
$resultado = $conexion->query($query);
if($resultado){
	header('Location: /TiemposdeCambios/bootstrap/proveedores.php');
} else{echo "errores";}
	
 ?>
<?php  
include ('php/conexion.php');
session_start();
if(isset($_SESSION['u_usuario']))
    {
    echo "session exitosa";
    } else
        {
        header('Location: login.php');
        }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>Agregar Usuario</title>
    <link rel="stylesheet" type="text/css" href="css/admin.css">
    <link rel="stylesheet" type="text/css" href="css/fontello.css">
    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="vendor/metisMenu/metisMenu.min.css" rel="stylesheet">

    <!-- DataTables CSS -->
    <link href="vendor/datatables-plugins/dataTables.bootstrap.css" rel="stylesheet">

    <!-- DataTables Responsive CSS -->
    <link href="vendor/datatables-responsive/dataTables.responsive.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="dist/css/sb-admin-2.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<?php  
include("php/header.php");
?>
<div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <h1 class="page-header">Agregar Usuario</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <form class="form-horizontal" role="form" action="php/guardar_proveedor.php" method="post" accept-charset="utf-8">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="icon-user"></i></span>
                            <input class="form-control" type="text" name="nombre" placeholder="Nombre de la empresa">
                        </div>
                        <div class="input-group">
                            <span class="input-group-addon"><i class="icon-doc-text"></i></span>
                            <input class="form-control" type="text" name="productos" placeholder="Productos de este proveedor">
                        </div>
                        <div class="input-group">
                            <span class="input-group-addon"><i class="icon-phone-3"></i></span>
                            <input class="form-control" type="text" name="telefono" placeholder="Teléfono">
                        </div>
                        <div class="input-group">
                            <span class="input-group-addon"><i class="icon-mail-1"></i></span>
                            <input class="form-control" type="email" name="email" placeholder="Email">
                        </div>
                        <div class="input-group">
                            <a class="btn btn-danger" href="proveedores.php">Cancelar</a>
                            <input class="btn btn-success" type="submit" name="enviar" value="Agregar">
                        </div>
                </form>
        </div>
</div>
    <script src="js/jquery-3.2.1.min.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="vendor/metisMenu/metisMenu.min.js"></script>

    <!-- DataTables JavaScript -->
    <script src="vendor/datatables/js/jquery.dataTables.min.js"></script>
    <script src="vendor/datatables-plugins/dataTables.bootstrap.min.js"></script>
    <script src="vendor/datatables-responsive/dataTables.responsive.js"></script>
    <script src="dist/js/sb-admin-2.js"></script>
</body>
</html>
    
asked by Jonatan Emanuel Villalon 03.11.2017 в 15:32
source

2 answers

1

Your problem is in the SQL query. Remember the phone in your database is of int , so you should remove the '$telefono' quotes, so it looks like this:

$query = "INSERT INTO proveedores (nombre,productos,telefono,email) values('$nombre','$productos',$telefono,'$email')";

I hope it works for you

    
answered by 03.11.2017 в 15:41
0

like says oscar , you have to check the data types and specify that what you are sending from php is According to what the mysql receives to manage the insert correctly, I advise you the following:

run the query first in mysql with any game and from php I think you should do it this way

$query = "INSERT INTO proveedores (nombre,productos,telefono,email) values('".$nombre."','".$productos."',".$telefono.",'".$email."')";

the points is so you can concatenate the values of the variables with the string, I hope that it works

    
answered by 03.11.2017 в 15:53