saramgsilva Posted March 4, 2006 at 08:51 PM Report #16819 Posted March 4, 2006 at 08:51 PM Topico de discusao inicial aqui GuestBook elaborado por bLd Bem eu deixo aqui um tutorial de Guestbook que acabei agr mesmo de criar. É muito simples e a partir dele podem alterar o que voçes bem entenderem 🙂 Tem duas paginas: guestbook.php (visualizar as assinaturas) guestbook_ass.php (assinar o guestbook) Vamos começar pelo mysql: CREATE TABLE `guestbook` ( `id` int(11) NOT NULL auto_increment, `nome` varchar(50) NOT NULL default '', `mail` varchar(30) NOT NULL default '', `mensagem` longtext NOT NULL, PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=3 ; Aqui fica o codigo das duas paginas! guestbook.php <?php require_once('Connections/conn.php'); ?> <?php $currentPage = $_SERVER["PHP_SELF"]; $maxRows_Rs_guest = 10; $pageNum_Rs_guest = 0; if (isset($_GET['pageNum_Rs_guest'])) { $pageNum_Rs_guest = $_GET['pageNum_Rs_guest']; } $startRow_Rs_guest = $pageNum_Rs_guest * $maxRows_Rs_guest; mysql_select_db($database_conn, $conn); $query_Rs_guest = "SELECT * FROM guestbook"; $query_limit_Rs_guest = sprintf("%s LIMIT %d, %d", $query_Rs_guest, $startRow_Rs_guest, $maxRows_Rs_guest); $Rs_guest = mysql_query($query_limit_Rs_guest, $conn) or die(mysql_error()); $row_Rs_guest = mysql_fetch_assoc($Rs_guest); if (isset($_GET['totalRows_Rs_guest'])) { $totalRows_Rs_guest = $_GET['totalRows_Rs_guest']; } else { $all_Rs_guest = mysql_query($query_Rs_guest); $totalRows_Rs_guest = mysql_num_rows($all_Rs_guest); } $totalPages_Rs_guest = ceil($totalRows_Rs_guest/$maxRows_Rs_guest)-1; $queryString_Rs_guest = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Rs_guest") == false && stristr($param, "totalRows_Rs_guest") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Rs_guest = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Rs_guest = sprintf("&totalRows_Rs_guest=%d%s", $totalRows_Rs_guest, $queryString_Rs_guest); ?><!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>Guestbook</title> <style type="text/css"> <!-- .style8 { font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #0066FF; } .style9 {font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; } --> </style> </head> <body> <p align="center"><a href="guestbook_ass.php">Assinar Guestbook</a></p> <table width="455" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <th width="114" valign="top" bordercolor="#0066FF" class="style8" scope="col"><span class="style8"></span></th> <th width="10" scope="col"> </th> <th width="331" scope="col"> </th> </tr> <?php do { ?> <tr> <th valign="top" bordercolor="#0066FF" class="style8" scope="row"><span class="style9">Nome:</span></th> <td> </td> <td><?php echo $row_Rs_guest['nome']; ?></td> </tr> <tr> <th valign="top" bordercolor="#0066FF" class="style8" scope="row"><span class="style9">Email:</span></th> <td> </td> <td><?php echo $row_Rs_guest['mail']; ?></td> </tr> <tr> <th height="85" valign="top" bordercolor="#0066FF" class="style8" scope="row"><span class="style9">Mensagem:</span></th> <td> </td> <td valign="top"><?php echo $row_Rs_guest['mensagem']; ?></td> </tr> <?php } while ($row_Rs_guest = mysql_fetch_assoc($Rs_guest)); ?> <tr> <th valign="top" scope="row"> </th> <td> </td> <td> </td> </tr> </table> <p align="center"> <table border="0" width="50%" align="center"> <tr> <td width="23%" align="center"><?php if ($pageNum_Rs_guest > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_Rs_guest=%d%s", $currentPage, 0, $queryString_Rs_guest); ?>">First</a> <?php } // Show if not first page ?> </td> <td width="31%" align="center"><?php if ($pageNum_Rs_guest > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_Rs_guest=%d%s", $currentPage, max(0, $pageNum_Rs_guest - 1), $queryString_Rs_guest); ?>">Previous</a> <?php } // Show if not first page ?> </td> <td width="23%" align="center"><?php if ($pageNum_Rs_guest < $totalPages_Rs_guest) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Rs_guest=%d%s", $currentPage, min($totalPages_Rs_guest, $pageNum_Rs_guest + 1), $queryString_Rs_guest); ?>">Next</a> <?php } // Show if not last page ?> </td> <td width="23%" align="center"><?php if ($pageNum_Rs_guest < $totalPages_Rs_guest) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Rs_guest=%d%s", $currentPage, $totalPages_Rs_guest, $queryString_Rs_guest); ?>">Last</a> <?php } // Show if not last page ?> </td> </tr> </table> </p> </body> </html> <?php mysql_free_result($Rs_guest); ?> E o guestbook_ass.php <?php require_once('Connections/conn.php'); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO guestbook (nome, mail, mensagem) VALUES (%s, %s, %s)", GetSQLValueString($_POST['nome_txt'], "text"), GetSQLValueString($_POST['email_txt'], "text"), GetSQLValueString($_POST['msg_txt'], "text")); mysql_select_db($database_conn, $conn); $Result1 = mysql_query($insertSQL, $conn) or die(mysql_error()); $insertGoTo = "guestbook.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?><!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>Guestbook</title> </head> <body> <form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST"> <table width="760" height="156" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <th width="90" scope="col"> </th> <th width="14" scope="col"> </th> <th width="656" scope="col"> </th> </tr> <tr> <th height="19" scope="row">Nome:</th> <td> </td> <td><input name="nome_txt" type="text" id="nome_txt" /></td> </tr> <tr> <th height="19" scope="row">Email:</th> <td> </td> <td><input name="email_txt" type="text" id="email_txt" /></td> </tr> <tr> <th height="37" scope="row">Mensagem:</th> <td> </td> <td><textarea name="msg_txt" cols="30" rows="5" id="msg_txt"></textarea></td> </tr> <tr> <th height="19" scope="row"> </th> <td> </td> <td> </td> </tr> <tr> <th scope="row"> </th> <td> </td> <td><input type="submit" name="Submit" value="Enviar" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"> </form> </body> </html> www.saramgsilva.com As minhas apps no WP7 Marketplace Youtube : Galinho - Windows Phone 7.5
deathseeker25 Posted March 4, 2006 at 08:59 PM Report #16826 Posted March 4, 2006 at 08:59 PM Só um senão: no código, podias inserir alguns comentários. A inserção de comentários faz com que o código seja mais perceptível aos olhos de outros programadores e ajuda os mais novatos a aprenderem como implementar certas coisas. 🙂 De resto, bom tutorial.
bLd Posted March 4, 2006 at 09:16 PM Report #16836 Posted March 4, 2006 at 09:16 PM INSERT INTO `guestbook` VALUES (1, 'Bruno', 'bruno@ptuser.org', 'teste de msg'); INSERT INTO `guestbook` VALUES (2, 'teste', 'teste', 'teste'); Eu achei bem nao por pk assim ng via os comentarios dos meus testes. Mas sendo assim basta introduzir esse dois codigos 🙂 .[ Once .SCP' , Allways .SCP']. o estádio a vibbrar a juve a cantar, ergue o teu poder, ergue a tua voz. SPORTING SOMOS NOS!
joninho Posted May 9, 2006 at 05:54 PM Report #26628 Posted May 9, 2006 at 05:54 PM Eu fiz um Guestbook mais simples, para quem nao preceber o da tofas... e tudo num unico fixeiro .php Requesitos: Saltar Logo para o DEFAULT nos cases, porque é o primeiro passo que a página faz, por isso é mais facil de esplicar assim MySql: Tabela Guestbook Campos: id tipo inteiro limite 255 (por exemplo) de tipo varchar limite 50 (aqui vai ser o remetente da mensagem a ser postada) mensagem tipo text (aqui vai ser armazenada a mensagem) date tipo varchar limite 50 pronto, axo que é só... aki vai: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Mensagens - GuestBook</title> <style type="text/css"> <!-- body { background-color: #156564; background-image: url(lol9.jpg); } .style2 { color: #0099FF; font-size: 18px; font-family: Verdana, Arial, Helvetica, sans-serif; } .style1{ color:#000000; font-size:18px; font-family:Geneva, Arial, Helvetica, sans-serif } --> </style><body> </head> <table width="499" border="1" bordercolor="#CC3300" cellpadding="0" cellspacing="0" align="center"> <!--DWLayoutTable--> <tr> <td width="495" height="185" valign="top" bgcolor="#CCCCCC"> <?php /* Ligacao a base de dados, substituir: SERVER: pelo vosso servidor USER: pelo vosso user da base de dados PASS: pela vossa password da base de dados BASE_DE_DADOS: pela vossa Base de dados */ $dbh=mysql_connect ("SERVER", "USER", "PASS") or die ('Não é possivel aceder à base de dados porque: ' . mysql_error()); mysql_select_db ("BASE_DE_DADOS"); ?> <?php // aqui a variavel $var vai receber um valor introduzido no endereço por exemplo index.php?action=lol a variavel $var vai ficar com o conteudo "lol", que é para depois usar os cases em vês de 2 páginas, como é cases e a variavel var logo no principio tem o conteudo "" e nao tenho nenhuma case para esse conteudo irá ser redireccionado para o default. $var=$_GET["action"]; //abrir os cases switch($var){ //case Enviar case "enviar": //bem vindo ao case enviar XD lol aqui é onde vai receber o conteudo do formulario para enviar para a base de dados... //a variavel date vai ficar com a data de hoje, e esta a função. $date = date("j/n/Y"); //a variavel nome vai receber o conteudo do formulario onde voce inseriu o nome.. $nome = $_POST["nome"]; //a variavel mensagem vai receber o conteudo do formulario onde voce interiu a mensagem, o nl2br é para fazer paragrafos ao longo do texto, respectivamente pelos paragrafos k meter.. $mensagem = nl2br($_POST["mensagem"]); //query para inserir o conteudo das variaveis na base de dados $query= "INSERT INTO `Guestbook` (`de` , `mensagem`, `date` ) VALUES ('$nome', '$mensagem',''$date')"; //se a query for bem sucedida entao apresenta o texto: "mensagem enviada" e uma hiperligação para voltar ao index.php if(mysql_query($query)){ echo "mensagem enviada!!!<br>"; echo '<a href=index.php>Voltar</a>'; //senao apresenta o texto: "mensagem nao foi enviada ocorreu um erro..." e uma hiperligacao para voltar ao index.php }else{ echo "mensagem nao foi enviada ocorreu um erro...<br>"; echo '<a href=index.php>Voltar</a>'; } //fexar o case ESTA ACABADO O SCRIPT DO GUESTBOOK break; //entao, o primeiro passo que a pagina faz é entrar aqui. e fazer o que o script manda... default: //aqui fazemos uma query para bd, que vai seleccionar o conteudo da tabela Guestbook $query="SELECT * FROM `Guestbook` WHERE 1"; //fazemos a query para dentro da variavel $nome, que vai ficar uma array. os nomes das variaveis podem ser alterados por si, desde que use direito e mude em todo lado.. $nome=mysql_query($query); /* agora fazemos um ciclo para imprimir no ecrã tudo o que tiver a array $nome tiver, nao sei bem explicar o ciclo XD mas sei que é para isso. ou seja imprime o que tiver na tabela, menos o id, se quiser tb pode imprimir o id, basta meter um echo $titulo[1], dependendo da posição desse campo...*/ while($titulo = mysql_fetch_row($nome)){ //imprime o remetente da mensagem... echo '<br><span class="style2">De: </span>'.'<span class="style1">'.$titulo[1].'</span>'; //imprime a data do local.. echo '<br><span class="style2">Data: </span>'.'<span class="style1">'.$titulo[4]."</span><br>"; //e por fim imprime a mensagem echo '<br><span class="style2">Mensagem: </span><br>'.'<span class="style1">'.$titulo[2].'</span><br>'; //separador das mensagens... fica mais bonito, assim pode separar umas das outras.. echo "=================================================================================="; // fexar o ciclo } //aqui fica o formulario para inserir na base de dados ?> //action e para onde o form vai mandar os dados, neste caso vai mandar para a nossa case enviar, porque vai meter o conteudo enviar na variavel e entao vai entrar na case "enviar" precebido? <form action="index.php?action=enviar" method="post"> Nome: <br />//aqui e a insercao do nome <input type="text" name="nome"/> <br /> Mensagem: <br /> // agora a da mensagem <textarea name="mensagem" cols = "70" rows="8"></textarea><br /> //estes sao os botoes submit para submeter o formulario e o reset para limpar tudo <input type="submit" value="Enviar"/> <input type="reset" value="Limpar tudo"/> //fexar o formulario </form> <? //e fexar o case default, agora faz de conta que uma pessoa mete texto no formulario, entao o script vai saltar para o case "enviar". dirija-se agora ao case"enviar" break; } ?></td> </tr> </table> </body> </html> <?php //fexa a ligacao a base de dados mysql_close($dbh); ?> não pude meter assentos porque o forum tava a delirar com os assentos :S podem ver o resultado disto aqui
unrealmanel Posted July 21, 2010 at 06:38 PM Report #340277 Posted July 21, 2010 at 06:38 PM Boas sou novo nestas areas, poderias dar-me uma ajuda? onde insiro os dados tipo user da bd, pass.. etc podem ajudar.me com isso? oBrigado ?
scorch Posted July 21, 2010 at 07:46 PM Report #340290 Posted July 21, 2010 at 07:46 PM Tens de ter uma base de dados MySQL. Sabes minimamente trabalhar com MySQL? PS: Não respondo a perguntas por mensagem que podem ser respondidas no fórum.
unrealmanel Posted July 22, 2010 at 11:46 AM Report #340378 Posted July 22, 2010 at 11:46 AM Sim tenho um conhecimento minimo, mas consigo criar a tabela, mas estou falando na conexao do guestbook com a tabela da BD, ou seja nome da bd etc.. :down:
scorch Posted July 22, 2010 at 12:24 PM Report #340384 Posted July 22, 2010 at 12:24 PM Isso em PHP, para te conectares a uma base de dados, é simples. Se procurares na net, encontras n tutoriais. 😉 //Não te esqueças de mudar o localhost, root e a password se for necessário. $link = mysql_connect("localhost", "root", ""); mysql_select_db("nome_da_base_de_dados"); PS: Não respondo a perguntas por mensagem que podem ser respondidas no fórum.
unrealmanel Posted July 22, 2010 at 12:40 PM Report #340387 Posted July 22, 2010 at 12:40 PM Onde posso inserir esse pequeno codigo? ? Desde ja agradeço
scorch Posted July 22, 2010 at 12:52 PM Report #340389 Posted July 22, 2010 at 12:52 PM Substitui o require_once('Connections/conn.php'); dos dois ficheiros por isso. PS: Não respondo a perguntas por mensagem que podem ser respondidas no fórum.
unrealmanel Posted July 22, 2010 at 01:02 PM Report #340390 Posted July 22, 2010 at 01:02 PM Bem, o erro que dava anteriormente desapareceu, mas veio outro.. :s Fiz o que me pediu ao digitar a mensagem da.me o seguinte erro: Notice: Undefined variable: database_conn in C:\Program Files\EasyPHP5.3.0\www\guest_bd\guestbook_ass.php on line 40 Notice: Undefined variable: conn in C:\Program Files\EasyPHP5.3.0\www\guest_bd\guestbook_ass.php on line 40 Warning: mysql_select_db() expects parameter 2 to be resource, null given in C:\Program Files\EasyPHP5.3.0\www\guest_bd\guestbook_ass.php on line 40 Notice: Undefined variable: conn in C:\Program Files\EasyPHP5.3.0\www\guest_bd\guestbook_ass.php on line 41 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\Program Files\EasyPHP5.3.0\www\guest_bd\guestbook_ass.php on line 41
scorch Posted July 23, 2010 at 09:33 AM Report #340543 Posted July 23, 2010 at 09:33 AM Mostra o código todo que tens. PS: Não respondo a perguntas por mensagem que podem ser respondidas no fórum.
unrealmanel Posted July 23, 2010 at 11:32 AM Report #340568 Posted July 23, 2010 at 11:32 AM Fui ao phpmyadmin e digitei bd para a criação da base de dados, logo cliquei em sql, e fiz past do codigo da tabela.. sos codigos que tenho é os seguintes: guestbook.php <?php $link = mysql_connect("localhost", "root", ""); mysql_select_db("bd"); ?> <?php $currentPage = $_SERVER["PHP_SELF"]; $maxRows_Rs_guest = 10; $pageNum_Rs_guest = 0; if (isset($_GET['pageNum_Rs_guest'])) { $pageNum_Rs_guest = $_GET['pageNum_Rs_guest']; } $startRow_Rs_guest = $pageNum_Rs_guest * $maxRows_Rs_guest; mysql_select_db($database_conn, $conn); $query_Rs_guest = "SELECT * FROM guestbook"; $query_limit_Rs_guest = sprintf("%s LIMIT %d, %d", $query_Rs_guest, $startRow_Rs_guest, $maxRows_Rs_guest); $Rs_guest = mysql_query($query_limit_Rs_guest, $conn) or die(mysql_error()); $row_Rs_guest = mysql_fetch_assoc($Rs_guest); if (isset($_GET['totalRows_Rs_guest'])) { $totalRows_Rs_guest = $_GET['totalRows_Rs_guest']; } else { $all_Rs_guest = mysql_query($query_Rs_guest); $totalRows_Rs_guest = mysql_num_rows($all_Rs_guest); } $totalPages_Rs_guest = ceil($totalRows_Rs_guest/$maxRows_Rs_guest)-1; $queryString_Rs_guest = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Rs_guest") == false && stristr($param, "totalRows_Rs_guest") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Rs_guest = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Rs_guest = sprintf("&totalRows_Rs_guest=%d%s", $totalRows_Rs_guest, $queryString_Rs_guest); ?><!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>Guestbook</title> <style type="text/css"> <!-- .style8 { font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #0066FF; } .style9 {font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; } --> </style> </head> <body> <p align="center"><a href="guestbook_ass.php">Assinar Guestbook</a></p> <table width="455" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <th width="114" valign="top" bordercolor="#0066FF" class="style8" scope="col"><span class="style8"></span></th> <th width="10" scope="col"> </th> <th width="331" scope="col"> </th> </tr> <?php do { ?> <tr> <th valign="top" bordercolor="#0066FF" class="style8" scope="row"><span class="style9">Nome:</span></th> <td> </td> <td><?php echo $row_Rs_guest['nome']; ?></td> </tr> <tr> <th valign="top" bordercolor="#0066FF" class="style8" scope="row"><span class="style9">Email:</span></th> <td> </td> <td><?php echo $row_Rs_guest['mail']; ?></td> </tr> <tr> <th height="85" valign="top" bordercolor="#0066FF" class="style8" scope="row"><span class="style9">Mensagem:</span></th> <td> </td> <td valign="top"><?php echo $row_Rs_guest['mensagem']; ?></td> </tr> <?php } while ($row_Rs_guest = mysql_fetch_assoc($Rs_guest)); ?> <tr> <th valign="top" scope="row"> </th> <td> </td> <td> </td> </tr> </table> <p align="center"> <table border="0" width="50%" align="center"> <tr> <td width="23%" align="center"><?php if ($pageNum_Rs_guest > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_Rs_guest=%d%s", $currentPage, 0, $queryString_Rs_guest); ?>">First</a> <?php } // Show if not first page ?> </td> <td width="31%" align="center"><?php if ($pageNum_Rs_guest > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_Rs_guest=%d%s", $currentPage, max(0, $pageNum_Rs_guest - 1), $queryString_Rs_guest); ?>">Previous</a> <?php } // Show if not first page ?> </td> <td width="23%" align="center"><?php if ($pageNum_Rs_guest < $totalPages_Rs_guest) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Rs_guest=%d%s", $currentPage, min($totalPages_Rs_guest, $pageNum_Rs_guest + 1), $queryString_Rs_guest); ?>">Next</a> <?php } // Show if not last page ?> </td> <td width="23%" align="center"><?php if ($pageNum_Rs_guest < $totalPages_Rs_guest) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Rs_guest=%d%s", $currentPage, $totalPages_Rs_guest, $queryString_Rs_guest); ?>">Last</a> <?php } // Show if not last page ?> </td> </tr> </table> </p> </body> </html> <?php mysql_free_result($Rs_guest); ?> guestbook_ass.php <?php $link = mysql_connect("localhost", "root", ""); mysql_select_db("bd"); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO guestbook (nome, mail, mensagem) VALUES (%s, %s, %s)", GetSQLValueString($_POST['nome_txt'], "text"), GetSQLValueString($_POST['email_txt'], "text"), GetSQLValueString($_POST['msg_txt'], "text")); mysql_select_db($database_conn, $conn); $Result1 = mysql_query($insertSQL, $conn) or die(mysql_error()); $insertGoTo = "guestbook.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?><!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>Guestbook</title> </head> <body> <form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST"> <table width="760" height="156" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <th width="90" scope="col"> </th> <th width="14" scope="col"> </th> <th width="656" scope="col"> </th> </tr> <tr> <th height="19" scope="row">Nome:</th> <td> </td> <td><input name="nome_txt" type="text" id="nome_txt" /></td> </tr> <tr> <th height="19" scope="row">Email:</th> <td> </td> <td><input name="email_txt" type="text" id="email_txt" /></td> </tr> <tr> <th height="37" scope="row">Mensagem:</th> <td> </td> <td><textarea name="msg_txt" cols="30" rows="5" id="msg_txt"></textarea></td> </tr> <tr> <th height="19" scope="row"> </th> <td> </td> <td> </td> </tr> <tr> <th scope="row"> </th> <td> </td> <td><input type="submit" name="Submit" value="Enviar" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"> </form> </body> </html> Agradeço imenso a ajuda ?
scorch Posted July 23, 2010 at 03:37 PM Report #340608 Posted July 23, 2010 at 03:37 PM Mas os erros estão no guestbook_ass.php, como dizem as mensagens. Era esse que eu queria. 😕 PS: Não respondo a perguntas por mensagem que podem ser respondidas no fórum.
unrealmanel Posted July 23, 2010 at 06:34 PM Report #340638 Posted July 23, 2010 at 06:34 PM Como assim? que devo alterar? :s
scorch Posted July 23, 2010 at 07:21 PM Report #340640 Posted July 23, 2010 at 07:21 PM Tu mostraste-me o ficheiro guestbook.php, mas os erros estão no ficheiro guestbook_ass.php. É o segundo ficheiro que eu preciso que tu me mostres. 😕 PS: Não respondo a perguntas por mensagem que podem ser respondidas no fórum.
unrealmanel Posted July 23, 2010 at 07:23 PM Report #340641 Posted July 23, 2010 at 07:23 PM Que tipo de erro se encontra? guestbook_ass.php <?php $link = mysql_connect("localhost", "root", ""); mysql_select_db("bd"); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO guestbook (nome, mail, mensagem) VALUES (%s, %s, %s)", GetSQLValueString($_POST['nome_txt'], "text"), GetSQLValueString($_POST['email_txt'], "text"), GetSQLValueString($_POST['msg_txt'], "text")); mysql_select_db($database_conn, $conn); $Result1 = mysql_query($insertSQL, $conn) or die(mysql_error()); $insertGoTo = "guestbook.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?><!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>Guestbook</title> </head> <body> <form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST"> <table width="760" height="156" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <th width="90" scope="col"> </th> <th width="14" scope="col"> </th> <th width="656" scope="col"> </th> </tr> <tr> <th height="19" scope="row">Nome:</th> <td> </td> <td><input name="nome_txt" type="text" id="nome_txt" /></td> </tr> <tr> <th height="19" scope="row">Email:</th> <td> </td> <td><input name="email_txt" type="text" id="email_txt" /></td> </tr> <tr> <th height="37" scope="row">Mensagem:</th> <td> </td> <td><textarea name="msg_txt" cols="30" rows="5" id="msg_txt"></textarea></td> </tr> <tr> <th height="19" scope="row"> </th> <td> </td> <td> </td> </tr> <tr> <th scope="row"> </th> <td> </td> <td><input type="submit" name="Submit" value="Enviar" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"> </form> </body> </html>
scorch Posted July 23, 2010 at 07:44 PM Report #340644 Posted July 23, 2010 at 07:44 PM Assim já deve funcionar: guestbook_ass.php <?php $link = mysql_connect("localhost", "root", ""); mysql_select_db("bd"); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO guestbook (nome, mail, mensagem) VALUES (\"%s\", \"%s\", \"%s\")", GetSQLValueString($_POST['nome_txt'], "text"), GetSQLValueString($_POST['email_txt'], "text"), GetSQLValueString($_POST['msg_txt'], "text")); $Result1 = mysql_query($insertSQL, $link) or die(mysql_error()); $insertGoTo = "guestbook.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?><!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>Guestbook</title> </head> <body> <form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST"> <table width="760" height="156" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <th width="90" scope="col"> </th> <th width="14" scope="col"> </th> <th width="656" scope="col"> </th> </tr> <tr> <th height="19" scope="row">Nome:</th> <td> </td> <td><input name="nome_txt" type="text" id="nome_txt" /></td> </tr> <tr> <th height="19" scope="row">Email:</th> <td> </td> <td><input name="email_txt" type="text" id="email_txt" /></td> </tr> <tr> <th height="37" scope="row">Mensagem:</th> <td> </td> <td><textarea name="msg_txt" cols="30" rows="5" id="msg_txt"></textarea></td> </tr> <tr> <th height="19" scope="row"> </th> <td> </td> <td> </td> </tr> <tr> <th scope="row"> </th> <td> </td> <td><input type="submit" name="Submit" value="Enviar" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"> </form> </body> </html> PS: Não respondo a perguntas por mensagem que podem ser respondidas no fórum.
unrealmanel Posted July 23, 2010 at 07:48 PM Report #340645 Posted July 23, 2010 at 07:48 PM Bem.. Ainda não esta resultando.. a assinatura esta funcionando, mas ao confirmar.. da-me o seguinte erro. Notice: Undefined variable: database_conn in C:\Program Files\EasyPHP5.3.0\www\guest_bd\guestbook.php on line 13 Notice: Undefined variable: conn in C:\Program Files\EasyPHP5.3.0\www\guest_bd\guestbook.php on line 13 Warning: mysql_select_db() expects parameter 2 to be resource, null given in C:\Program Files\EasyPHP5.3.0\www\guest_bd\guestbook.php on line 13 Notice: Undefined variable: conn in C:\Program Files\EasyPHP5.3.0\www\guest_bd\guestbook.php on line 16 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\Program Files\EasyPHP5.3.0\www\guest_bd\guestbook.php on line 16 :S 😕
scorch Posted July 23, 2010 at 08:10 PM Report #340651 Posted July 23, 2010 at 08:10 PM Agora mete isto no ficheiro guestbook.php. Em principio já deve funcionar. 😕 <?php $link = mysql_connect("localhost", "root", ""); mysql_select_db("bd"); ?> <?php $currentPage = $_SERVER["PHP_SELF"]; $maxRows_Rs_guest = 10; $pageNum_Rs_guest = 0; if (isset($_GET['pageNum_Rs_guest'])) { $pageNum_Rs_guest = $_GET['pageNum_Rs_guest']; } $startRow_Rs_guest = $pageNum_Rs_guest * $maxRows_Rs_guest; $query_Rs_guest = "SELECT * FROM guestbook"; $query_limit_Rs_guest = sprintf("%s LIMIT %d, %d", $query_Rs_guest, $startRow_Rs_guest, $maxRows_Rs_guest); $Rs_guest = mysql_query($query_limit_Rs_guest, $link) or die(mysql_error()); $row_Rs_guest = mysql_fetch_assoc($Rs_guest); if (isset($_GET['totalRows_Rs_guest'])) { $totalRows_Rs_guest = $_GET['totalRows_Rs_guest']; } else { $all_Rs_guest = mysql_query($query_Rs_guest); $totalRows_Rs_guest = mysql_num_rows($all_Rs_guest); } $totalPages_Rs_guest = ceil($totalRows_Rs_guest/$maxRows_Rs_guest)-1; $queryString_Rs_guest = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Rs_guest") == false && stristr($param, "totalRows_Rs_guest") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Rs_guest = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Rs_guest = sprintf("&totalRows_Rs_guest=%d%s", $totalRows_Rs_guest, $queryString_Rs_guest); ?><!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>Guestbook</title> <style type="text/css"> <!-- .style8 { font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #0066FF; } .style9 {font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif; } --> </style> </head> <body> <p align="center"><a href="guestbook_ass.php">Assinar Guestbook</a></p> <table width="455" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <th width="114" valign="top" bordercolor="#0066FF" class="style8" scope="col"><span class="style8"></span></th> <th width="10" scope="col"> </th> <th width="331" scope="col"> </th> </tr> <?php do { ?> <tr> <th valign="top" bordercolor="#0066FF" class="style8" scope="row"><span class="style9">Nome:</span></th> <td> </td> <td><?php echo $row_Rs_guest['nome']; ?></td> </tr> <tr> <th valign="top" bordercolor="#0066FF" class="style8" scope="row"><span class="style9">Email:</span></th> <td> </td> <td><?php echo $row_Rs_guest['mail']; ?></td> </tr> <tr> <th height="85" valign="top" bordercolor="#0066FF" class="style8" scope="row"><span class="style9">Mensagem:</span></th> <td> </td> <td valign="top"><?php echo $row_Rs_guest['mensagem']; ?></td> </tr> <?php } while ($row_Rs_guest = mysql_fetch_assoc($Rs_guest)); ?> <tr> <th valign="top" scope="row"> </th> <td> </td> <td> </td> </tr> </table> <p align="center"> <table border="0" width="50%" align="center"> <tr> <td width="23%" align="center"><?php if ($pageNum_Rs_guest > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_Rs_guest=%d%s", $currentPage, 0, $queryString_Rs_guest); ?>">First</a> <?php } // Show if not first page ?> </td> <td width="31%" align="center"><?php if ($pageNum_Rs_guest > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_Rs_guest=%d%s", $currentPage, max(0, $pageNum_Rs_guest - 1), $queryString_Rs_guest); ?>">Previous</a> <?php } // Show if not first page ?> </td> <td width="23%" align="center"><?php if ($pageNum_Rs_guest < $totalPages_Rs_guest) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Rs_guest=%d%s", $currentPage, min($totalPages_Rs_guest, $pageNum_Rs_guest + 1), $queryString_Rs_guest); ?>">Next</a> <?php } // Show if not last page ?> </td> <td width="23%" align="center"><?php if ($pageNum_Rs_guest < $totalPages_Rs_guest) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_Rs_guest=%d%s", $currentPage, $totalPages_Rs_guest, $queryString_Rs_guest); ?>">Last</a> <?php } // Show if not last page ?> </td> </tr> </table> </p> </body> </html> <?php mysql_free_result($Rs_guest); ?> guestbook_ass.php <?php $link = mysql_connect("localhost", "root", ""); mysql_select_db("bd"); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO guestbook (nome, mail, mensagem) VALUES (%s, %s, %s)", GetSQLValueString($_POST['nome_txt'], "text"), GetSQLValueString($_POST['email_txt'], "text"), GetSQLValueString($_POST['msg_txt'], "text")); mysql_select_db($database_conn, $conn); $Result1 = mysql_query($insertSQL, $conn) or die(mysql_error()); $insertGoTo = "guestbook.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?><!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>Guestbook</title> </head> <body> <form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST"> <table width="760" height="156" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <th width="90" scope="col"> </th> <th width="14" scope="col"> </th> <th width="656" scope="col"> </th> </tr> <tr> <th height="19" scope="row">Nome:</th> <td> </td> <td><input name="nome_txt" type="text" id="nome_txt" /></td> </tr> <tr> <th height="19" scope="row">Email:</th> <td> </td> <td><input name="email_txt" type="text" id="email_txt" /></td> </tr> <tr> <th height="37" scope="row">Mensagem:</th> <td> </td> <td><textarea name="msg_txt" cols="30" rows="5" id="msg_txt"></textarea></td> </tr> <tr> <th height="19" scope="row"> </th> <td> </td> <td> </td> </tr> <tr> <th scope="row"> </th> <td> </td> <td><input type="submit" name="Submit" value="Enviar" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"> </form> </body> </html> PS: Não respondo a perguntas por mensagem que podem ser respondidas no fórum.
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