0
Hello :) I am starting learning with PHP, trying to insert data from the database. Although no error returns, 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>
See if there are any errors:
$res=mysqli_query($con,$insere) or die(mysqli_error($con);
– rray
@rray correcting:
die(mysqli_error($con));
– Don't Panic
A good practice is to inform the fields after the table
tb_cadastro(coluna1,coluna2....)
– Don't Panic
$email
is a string (varchar), and must be in single quotes in your SQL– Don't Panic
Thanks! The error was this small detail of the simple quotes! error appeared when place echo mysqli_error($con);
– mazzu
Keep in mind that the value of $tel=9999-99999; will return -90000. To return 9999-99999 put it in quotes according to the other $tel="9999-99999";
– user60252