-1
I’m trying to insert data via form in PHP. However, I’m having an error, I can’t find this error at all.
As I said, I’m wanting to enter data, via the SELECT INTO
Observe:
insert.php, this is the tab where I will insert the data.
<h3>Formulário de Cadastro de Sinaps</h3><br>
<form name="Cadastro" action="insere_dados.php" method="POST">
<label>Nome do programa: </label>
<input type="text" name="programa" size="30"><br>
<label>versa do programa: </label>
<input type="text" name="versaoprograma" size="45"><br>
<label>Data de Publicação: </label>
<input type="text" name="data" size="45"><br>
<br>
<input type="submit" name="enviar" value="Enviar">
</form>
insere_data.php, this tab will make the insert function.php
<?php
$programa = $_POST['programa'];
$versaoprograma = $_POST['versaoprograma'];
$data = $_POST['data'];
$strcon = mysqli_connect('localhost','root','','atualizacao') or die('Erro ao conectar ao banco de dados');
$sql = "INSERT INTO geral (nomedopograma, versaodoprograma, datadoprograma) VALUES ('$programa', '$versaoprograma', '$data')";
mysqli_query($strcon,$sql) or die("Erro ao tentar cadastrar registro");
mysqli_close($strcon);
echo "Cliente cadastrado com sucesso!";
?>
Atualized.php, this tab will receive the data from insert.php
<?php
// Propriedades BD
define("HOST", "localhost");
define("USER", "root");
define("PASS", "");
define("BDNAME", "atualizacao");
@mysql_connect(HOST, USER, PASS) or die("Não foi possivel se conectar ao servidor");
mysql_select_db(BDNAME) or die("Não foi possível se conectar ao banco de dados") ;
?>
<?php
$sql = mysql_query("SELECT * FROM geral");
while($exibe = mysql_fetch_assoc($sql)){
echo "<ul class='col-md-12 item1'>";
echo "<li class='nomedoprograma'>".$exibe["nomedoprograma"]."</li>";
echo "<li class='versao'>".$exibe["versaodoprograma"]."</li>";
echo "<li class='atualizacao'>".$exibe["datadoprograma"]."</li>";
echo "</ul>";
}
?>
When I fill in the data and click send, the only message that appears is Error trying to register,
Database
-- phpMyAdmin SQL Dump -- version 4.6.4 -- https://www.phpmyadmin.net/ -- -- Host: 127.0.0.1 -- Generation Time: 24-Abr-2017 às 15:32 -- Versão do servidor: 5.7.14 -- PHP Version: 5.6.25 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `atualizacao` -- -- -------------------------------------------------------- -- -- Estrutura da tabela `geral` -- CREATE TABLE `geral` ( `nomedoprograma` varchar(50) CHARACTER SET utf8 NOT NULL, `versaodoprograma` varchar(20) CHARACTER SET utf8 NOT NULL, `datadoprograma` date NOT NULL, `comentarios` varchar(1024) CHARACTER SET utf8 NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Extraindo dados da tabela `geral` -- INSERT INTO `geral` (`nomedoprograma`, `versaodoprograma`, `datadoprograma`, `comentarios`) VALUES ('Sinap280', 'Versao 200', '2017-04-24', ''), ('Sinap280', 'Versao 200', '2017-04-24', ''), ('', 'versao100', '2017-04-24', ''), ('Sinap 8024', '1090', '2017-04-24', ''); /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
This is the database.
During the debug, change the
die("Erro ao tentar cadastrar registro");
by one that shows the actual error returned, which gets easier:die(mysqli_error($strcon));
- This for debug only, in production it makes no sense to reveal the structure of your application to the end user.– Bacco
Parse error: syntax error, Unexpected 'mysqli_close' (T_STRING) in C: wamp64 www Duotec - Sistemas insere_dados.php on line 9 appeared this error
– José Júnior
Actually the error is another "Unknown column 'namephotogram' in 'field list'" I think I’ve found
– José Júnior
Yeah, there’s an R missing there. The most important thing is to get used to using the
mysql_error
to facilitate development. And once ready, take off the screen output (and maybe send to error log, for example)– Bacco
Yes yes, thank you very much
– José Júnior