Database does not save data in php, although it does not return error [closed]

0

Hello :) I'm starting to learn with PHP, trying to insert data from the database. Although no return error, the data is not saved. Here is the code:

    <?php

    $con=mysqli_connect("localhost","mazzu","");
    mysqli_select_db($con,"aulasphp");

    $nome="Matheus";
    $username="mazzu";
    $email="[email protected]";
    $senha="123";
    $tel=9999-99999;
    $status="ok";
    $obs="ok";


    $insere="insert into tb_cadastro values (NULL ,'$nome','$username',$email,'$senha','$tel','$status','$obs')";
    $res=mysqli_query($con,$insere);




    mysqli_close($con);

?>



<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>Aula 30</title>
    </head>

    <body>
    </body>
</html>
    
asked by anonymous 08.07.2017 / 20:01

2 answers

2

There is probably an error with your SQL that is not reported natively by PHP. To see the error generated in MySQL use the php function mysqli_error link

Put a echo mysqli_error($con); after you execute the query (and before closing the connection).

    
08.07.2017 / 20:09
0

It may be type mismatch in your table. Ex: trying to insert a varchar into an int, make sure this is not it. If not, use the mysqli_error.

$res=mysqli_query($con,$insere) or die (mysqli_error($con));
    
08.07.2017 / 20:48