Blue_Acid Posted March 3, 2006 at 04:56 PM Report Share #16556 Posted March 3, 2006 at 04:56 PM boas ppl, comecei agora a dar uns toques na programação PHP, e queria começar por uma sistema de Newsletters a parte do registo, já fiz a base de dados apenas com os campos "Nome" e "Mail", tinha o campo "ID" de auto incremento, mas tirei pk pensei k fosse isso k m estava a avariar o script. Tenho apenas duas páginas o index, onde se adiciona o nome e o mail, e faz logo a listagem dos inscritos, e tenho o ficheiro PHP k adiciona, alguem me pode verificar o codigo e dizer-me pk fico com os campos vazios. Obrigado <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>adicionar news</title> </head> <body> <form method="POST" action="add_new.php"> <label>Nome <input type="text" name="nome" /> </label> <label>e-mail <input type="text" name="mail" /> </label> <label> <input type="submit" name="Enviar" value="Enviar" /> </label> </form> <? $msg[0] = "Erro ao Conectar"; $msg[1] = "Erro ao aceder a Base de Dados"; //Ligar a Base de Dados $connect = mysql_pconnect ("localhost","admnews","adm") or die ($msg[0]); mysql_select_db("newsl", $connect) or die ($msg[1]); ?> Listagem de Associados: <table border="1"> <tr> <td>Nome</td> <td>E-Mail</td> </tr> <? // completar a tabela $query = "SELECT nome,mail FROM add_new"; $resultado = mysql_query($query,$connect); while ($linha = mysql_fetch_array ($resultado)) { ?> <tr> <td width="200"> <? echo $linha ['nome'];?></td> <td width="600"> <? echo $linha ['mail'];?></td> </tr> <? } ?> </table> </body> </html> Este é o PHP k adiciona <? global $nome; global $mail; $nome = trim($nome); $mail = trim($mail); $connect = mysql_connect("localhost","admnews","adm") or die ("Erro a ligar a BD"); $insert = "INSERT into add_new values ('$nome','$mail')"; mysql_db_query("newsl", $insert, $connect); header("Location: index.php"); ?> Obrigado Pessoal, bom fim de semana 🙂 SIGNIFICADOS: WWW: Wait,wait,wait... HTML: Hoje Ta Mais Lento.KEYBOARD: Dispositivo usado para entrada de erros no Computador. Link to comment Share on other sites More sharing options...
deathseeker25 Posted March 3, 2006 at 05:15 PM Report Share #16560 Posted March 3, 2006 at 05:15 PM Boas, Não queres mostrar a estrutura da base de dados para eu testar aqui o problema? É que só assim conseguirei dar uma ajuda... 🙂 Link to comment Share on other sites More sharing options...
Blue_Acid Posted March 3, 2006 at 05:18 PM Author Report Share #16561 Posted March 3, 2006 at 05:18 PM ok, então eu fiz assim um file SQL tb para começar a brincar com isto. create table add_new( ID int not null auto_increment primary key, nome varchar(40), mail varchar(30) ); vou dp voltar a inserir novamente o campo ID, e como é automatico é preciso fazer alguma coisa no codigo para adicionar autmaticament? Um Abraço 🙂 SIGNIFICADOS: WWW: Wait,wait,wait... HTML: Hoje Ta Mais Lento.KEYBOARD: Dispositivo usado para entrada de erros no Computador. Link to comment Share on other sites More sharing options...
satanuke Posted March 3, 2006 at 09:02 PM Report Share #16620 Posted March 3, 2006 at 09:02 PM Usa o $_POST não uses variaveis globais... // global $nome; // global $mail; $nome = $_POST['nome']; $mail = $_POST['mail']; $nome = trim($nome); $mail = trim($mail); $connect = mysql_connect("localhost","admnews","adm") or die ("Erro a ligar a BD"); $insert = "INSERT into add_new values ('$nome','$mail')"; mysql_db_query("newsl", $insert, $connect); header("Location: index.php"); tek.readers blog Link to comment Share on other sites More sharing options...
Ped@ntilva Posted March 9, 2006 at 04:56 PM Report Share #17556 Posted March 9, 2006 at 04:56 PM Eu também gosto mais do POST... E que erro é que te dá quanto ao MySQL? Link to comment Share on other sites More sharing options...
Blue_Acid Posted March 10, 2006 at 11:27 AM Author Report Share #17626 Posted March 10, 2006 at 11:27 AM Obrigado, assunto resolvido, é mesmo o POST, já bomba, como eu tenho estado a estudar por um tut brazuca, devia ser com a versão do php mais antiga. Onrigado pelo F1 🙂 SIGNIFICADOS: WWW: Wait,wait,wait... HTML: Hoje Ta Mais Lento.KEYBOARD: Dispositivo usado para entrada de erros no Computador. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now