Jump to content

Recommended Posts

Posted

Boas, como eh k posso fazer um Livro de visitas?  eu ja sei passar texto de uma pagina htm para outra php com o method post ou get,  tipo:

1- abro o Enviar.htm

2- escrevo nos campos k kero & fasso submeter

3- tem lah os dados... (na ler.php)

4- enviar outra vex

5- os dados sao substituidos( :X cm eh k fasso para acrescentar em ves d substutuir? :X)

ja preceberam o k kero fazer? e assim ja sei fazer um guestbook 👍 lol Cumps...

  • Replies 48
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted

Tens que ir ao phpMyAdmin e crias uma base de dados com o nome que pretenderes.

Depois crias as tabelas que achares necessárias.

Depois é só fazer com  que grave os ficheiros na BD.

e o tipo do atributo é prai um memo...não...acho que isto não é muito dificil de implementar...prai um textarea, e depois guardar o k foi escrito na bdd... 😄 arranjei um novo host, que suporta php e tem 500mb, para poder fazer isso...ai ai...tenho 1 curso pra acabar... e só penso em programar...bem tou adorar php !!  😁

Posted

mySQL é bem mais simples... mas tas a baralhar as coisas... Ainda não tens capacidade para o mySQL... se isso fosse tão simples estaria em primeiro lugar nos tutoriais de PHP

Preocupa-te primeiro em acabar os tutoriais e em programar bom PHP para depois aprenderes coisas novas 👍

Posted

eu já fiz questão de apagar os meus...

tofas: Estou a responder segundo percebi 👍 No meu caso eu meto as variaveis do campo das mensagens num campo do tipo tinytext. Não sei se estou a fazer bem ou mal mas sei que resulta e não tenho que me preocupar com o espaço 😛

Posted

o que quero saber é , o texto do guestbook é colocado numa variavel....vai ser 1 string... mas quando guardas na base de dados é uma varchar?? ou usas que tipo??  :dontgetit:

Eu costumo guardar como VARCHAR, mas quando quero guardar conteúdos muito longos guardo em TEXT.

Posted

Boas, como eh k posso fazer um Livro de visitas?  eu ja sei passar texto de uma pagina htm para outra php com o method post ou get,  tipo:

1- abro o Enviar.htm

2- escrevo nos campos k kero & fasso submeter

3- tem lah os dados... (na ler.php)

4- enviar outra vex

5- os dados sao substituidos( :X cm eh k fasso para acrescentar em ves d substutuir? :X)

ja preceberam o k kero fazer? e assim ja sei fazer um guestbook 👍 lol Cumps...

Tas c duvidas em como acrescentar certo...

tenta isto:

$ficheiro_txt = "ficheiro.txt";
$ficheiro = fopen($ficheiro_txt, 'a'); 
Posted

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 🙂

O sistema de Guestbook ja tem incrementado uma paginação, mas que só é mostrada ao fim de inserção de + de  registos.

( A Paginação foi utilizada a partir dos codigos que o Dreamweaver fornece)

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>

Envio o script todo, basta ir a pasta Connections e alterar os vossos dados

.[ Once .SCP' , Allways .SCP']. o estádio a vibbrar a juve a cantar, ergue o teu poder, ergue a tua voz. SPORTING SOMOS NOS!

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.