taudujas Posted August 3, 2004 Report Share Posted August 3, 2004 Estava montando este sisteminha de artigos, mas não esta gravando no banco, eu já revirei o script em busca de erros e não aparece nenhum erro.// enviartigo.php<html> <head> <title>Envio de Artigos - Muitação.com</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form name="form1" method="post" action="gartigo.php"> <table width="55%" border="0" align="center"> <tr> <td width="21%"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Titulo:</strong></font></td> <td width="79%"><input name="titulo" type="text" id="titulo2"></td> </tr> <tr> <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Categoria:</strong></font></td> <td><select name="categoria" id="select"> <option value="PHP">PHP</option> </select></td> </tr> <tr> <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Artigo:</strong></font></td> <td><textarea name="artigo" cols="70" rows="15" id="textarea"></textarea></td> </tr> <tr> <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> </font></td> <td><input type="submit" name="Submit" value="Enviar artigo"></td> </tr> </table> </form> </body> </html> // gartigo.php <? include "config.php"; $titulo = strip_tags $_POST['titulo']; $categoria = strip_tags $_POST['categoria']; $artigo = strip_tags $_POST['artigo']; $insere = "insert into artigos(titulo, categoria, artigo)VALUES('$titulo','$categoria', '$artigo')"; mysql_query($insere); echo "Erro: ". mysql_error(); ?>Banco de dadosCREATE TABLE `artigos` ( `id` int(10) unsigned NOT NULL auto_increment, `titulo` varchar(100) NOT NULL default '', `categoria` varchar(80) NOT NULL default '', `descricao` text NOT NULL, `comentarios` varchar(200) NOT NULL default '', PRIMARY KEY (`id`)) TYPE=MyISAM AUTO_INCREMENT=1 ; Quote Link to comment Share on other sites More sharing options...
0 sadrack Posted August 3, 2004 Report Share Posted August 3, 2004 tem q colocar INSERT INTO em maiusculo$insere = "INSERT INTO artigos(titulo, categoria, artigo) VALUES('$titulo','$categoria', '$artigo')"; Quote Link to comment Share on other sites More sharing options...
0 taudujas Posted August 3, 2004 Author Report Share Posted August 3, 2004 Tentei mas não deu... Quote Link to comment Share on other sites More sharing options...
0 Error404 Posted August 3, 2004 Report Share Posted August 3, 2004 Faltaram espaços:$insere = "insert into artigos(titulo, categoria, artigo)VALUES('$titulo','$categoria', '$artigo')";tente$insere = "insert into artigos (titulo, categoria, artigo) VALUES ('$titulo','$categoria', '$artigo')"; Quote Link to comment Share on other sites More sharing options...
0 taudujas Posted August 3, 2004 Author Report Share Posted August 3, 2004 Mesmo assim não cadastrou..o que sera? Quote Link to comment Share on other sites More sharing options...
0 Error404 Posted August 3, 2004 Report Share Posted August 3, 2004 Faz aquilo que eu já te falei do mysql_error()...Assim você sempre descobre qual é o erro... Quote Link to comment Share on other sites More sharing options...
0 taudujas Posted August 3, 2004 Author Report Share Posted August 3, 2004 já fiz isso error, esta ai no arquivo em cima. Quote Link to comment Share on other sites More sharing options...
0 taudujas Posted August 3, 2004 Author Report Share Posted August 3, 2004 Aceito mais sugestoes, desde que sejam construtivas... Quote Link to comment Share on other sites More sharing options...
0 LuizFumes Posted August 3, 2004 Report Share Posted August 3, 2004 Ele da esses erros de cadastros quandovocê está tentando inserir um valor em um campo inexistente...ou senão, você está tentando cadastrar um valor, com valor igual ao antigo (se o campo for chave primaria)coloca antes do INSERT um monte de echo.. com todas as variaveis que você que cadastra, p/ ve se todas estão com o valor certo... ai checa os campos, ve se estão todos com nomes exatos... e ve se não esta tentando cadastrar chave primaria inválida Quote Link to comment Share on other sites More sharing options...
0 LuizFumes Posted August 3, 2004 Report Share Posted August 3, 2004 Ele da esses erros de cadastros quandovocê está tentando inserir um valor em um campo inexistente...ou senão, você está tentando cadastrar um valor, com valor igual ao antigo (se o campo for chave primaria)coloca antes do INSERT um monte de echo.. com todas as variaveis que você que cadastra, p/ ve se todas estão com o valor certo... ai checa os campos, ve se estão todos com nomes exatos... e ve se não esta tentando cadastrar chave primaria inválida Quote Link to comment Share on other sites More sharing options...
0 LuizFumes Posted August 3, 2004 Report Share Posted August 3, 2004 você não precisa do $_GET ou do $_POSTse no formulário você tem um campo chamado nome.... ex.<input name="txNome" type="text">na outra página basta você usar ele como variável..tipo:echo($txNome);ele já vai intender Quote Link to comment Share on other sites More sharing options...
0 LuizFumes Posted August 3, 2004 Report Share Posted August 3, 2004 e o erro está emCREATE TABLE `artigos` ( `id` int(10) unsigned NOT NULL auto_increment, `titulo` varchar(100) NOT NULL default '', `categoria` varchar(80) NOT NULL default '', `descricao` text NOT NULL, `comentarios` varchar(200) NOT NULL default '', PRIMARY KEY (`id`)) TYPE=MyISAM AUTO_INCREMENT=1 ;Olha o campo descrição.. ele está como NOT NULL e você não está inserindo nada nele.... Dai ele não pode inserir um valor NULL Quote Link to comment Share on other sites More sharing options...
0 taudujas Posted August 3, 2004 Author Report Share Posted August 3, 2004 Mas o categoria tem um campo option PHP e value PHP, então ele tem que cadastrar..concorda?? Quote Link to comment Share on other sites More sharing options...
0 taudujas Posted August 3, 2004 Author Report Share Posted August 3, 2004 Deu quase certo.. quando ignorei os $_POST ele cadastrou em branco, agora quando uso os $_POST ai ele não grava nada, nem da erro.. Quote Link to comment Share on other sites More sharing options...
0 LuizFumes Posted August 3, 2004 Report Share Posted August 3, 2004 esses errinhos em php é um inferno axa huhaa... eu aki no trampo, mecho com muito banco.. as veiz um errinho, fico a tarde toda procurando Quote Link to comment Share on other sites More sharing options...
0 taudujas Posted August 3, 2004 Author Report Share Posted August 3, 2004 é mas ainda não deu certo.. Quote Link to comment Share on other sites More sharing options...
0 LuizFumes Posted August 3, 2004 Report Share Posted August 3, 2004 ow loco... o que acontece agora? Quote Link to comment Share on other sites More sharing options...
0 taudujas Posted August 3, 2004 Author Report Share Posted August 3, 2004 ele não cadastra as informações olha como ta o gartigo.php<?//include "config.php";mysql_connect("localhost", "root", "");mysql_select_db(muitacao);//$titulo = strip_tags $_POST['titulo'];//$categoria = strip_tags $_POST['categoria'];//$artigo = strip_tags $_POST['artigo'];$insere = "insert into artigos(titulo, categoria, artigo) VALUES ('$titulo','$categoria', '$artigo')";mysql_query($insere);echo "Erro: ". mysql_error();?>Obs: mudei ele porque estou em outra maquina.. Quote Link to comment Share on other sites More sharing options...
0 LuizFumes Posted August 3, 2004 Report Share Posted August 3, 2004 CREATE TABLE `artigos` ( `id` int(10) unsigned NOT NULL auto_increment, `titulo` varchar(100) NOT NULL default '', `categoria` varchar(80) NOT NULL default '', `descricao` text NOT NULL, `comentarios` varchar(200) NOT NULL default '', PRIMARY KEY (`id`)) TYPE=MyISAM AUTO_INCREMENT=1 ;so como teste, tenta inserir um valor em toda a tabela... titulo, categoria, descricao, comentarios...porque são todos NOT NULL..faiz como teste isso, e ve o que da Quote Link to comment Share on other sites More sharing options...
0 taudujas Posted August 3, 2004 Author Report Share Posted August 3, 2004 Não, mas o campo comentarios é onde tera os comentarios depois do artigo adicionado entendeu?o banco é este agora:CREATE TABLE `artigos` ( `id` int(10) unsigned NOT NULL auto_increment, `titulo` varchar(100) NOT NULL default '', `categoria` varchar(80) NOT NULL default '', `artigo` text NOT NULL, `comentarios` varchar(200) NOT NULL default '', PRIMARY KEY (`id`)) TYPE=MyISAM AUTO_INCREMENT=9 ; Quote Link to comment Share on other sites More sharing options...
0 taudujas Posted August 3, 2004 Author Report Share Posted August 3, 2004 Pelo fato do campo id ser not null tem problema?? Quote Link to comment Share on other sites More sharing options...
0 griphon Posted August 4, 2004 Report Share Posted August 4, 2004 <?//include "config.php";mysql_connect("localhost", "root", "");mysql_select_db(muitacao);//$titulo = strip_tags $_POST['titulo'];//$categoria = strip_tags $_POST['categoria'];//$artigo = strip_tags $_POST['artigo'];$insere = "insert into artigos(titulo, categoria, artigo) VALUES ('$titulo','$categoria', '$artigo')";mysql_query($insere);echo "Erro: ". mysql_error();?>você já tentou separar as variáveis, tipo:$insere = "insert into artigos(titulo, categoria, artigo) VALUES ('".$titulo."','".$categoria."', '".$artigo."')"; Quote Link to comment Share on other sites More sharing options...
0 LuizFumes Posted August 4, 2004 Report Share Posted August 4, 2004 tira o NOT NULL do comentario então Quote Link to comment Share on other sites More sharing options...
Question
taudujas
Estava montando este sisteminha de artigos, mas não esta gravando no banco, eu já revirei o script em busca de erros e não aparece nenhum erro.
// enviartigo.php
// gartigo.phpBanco de dados
Link to comment
Share on other sites
22 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.