1
I am learning mysql and php, but is giving an error in the form, where even having been filled in it keeps asking to fill in the fields and does not record anything in the database table
<?php
$db = "progdesenv";
@mysql_connect("localhost", "root", "") or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db ($db);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="ckeditor/ckeditor.js"></script>
</head>
<body>
<form method="post" enctype="multipart/form-data">
Nome:<input type="text" name="nome"><br>
Idade:<input type="text" name="idade"><br>
Telefone:<input type="text" name="telefone"><br>
Mensagem<textarea class="ckeditor" name="editor1" cols="30" rows="10" ></textarea>
<input type="hidden" name="acao" value="enviado">
<input type="submit" value="Enviar Informações">
</form>
<?php
if(isset($_POST['acao']) && $_POST['acao'] == 'enviado'){
$nome = $_POST['nome'];
$idade = $_POST['idade'];
$telefone = $_POST['telefone'];
$editor1 = $_POST['editor1'];
if(empty($nome) || ($idade) || ($telefone) || ($editor1)){
echo "Preencha os campos corretamente";
}else{
$insereDados = msql_query("INSERT INTO formulario (nome, idade, telefone, editor1) VALUES ('$nome', '$idade', '$telefone', '$editor1' )");
echo "Enviado com sucesso!!";
}
}
?>
NAY use the family functions
mysql_*
. Use the ones of the familymysqli_*
or PDO. This function family has been discontinued and can be removed in the near future. And you should escape values before they go to the database. Read this answer to another question: http://answall.com/questions/579/por-que-n%C3%a3o-devo-usar-fun%C3%A7%C3%b5es-do tipo-mysql? lq=1– Ismael Miguel