mercoledì 16 ottobre 2013

Bacheca in PHP + MySQL

Piccolo esempio di bacheca realizzata con PHP e un database MySQL.
Scopo didattico, non adatto per altri utilizzi.
<html>
<head>
<b><big>Guestbook</big></b><br>
Here are a small messenger that is implemented by PHP and MySQL.<br>
Its aspect is very simple but behind the facade is a bit complicated. Enjoy!
</head>
<body>
<form method=GET action="bacheca.php">
<br>Welcome, please type your message here! (max 140 ch)<br>
Your name:<input type=text name="nome"></input><br>
<textarea name="testo" cols=80 rows=5 wrap=physical></textarea><br>
<input type=submit name="submit" value="submit"></input><br><br>

<?php
$username="";
$password="";
$database="";
$name = $_REQUEST["nome"];
$testo = $_REQUEST["testo"];
$data = date('d M y - H:i', time());
if($_REQUEST["submit"] == "submit"){
        mysql_connect(localhost,$username,$password);
@mysql_select_db($database)
    or die( "Impossibile selezionare il database dall'IF.");
$query="INSERT INTO bacheca VALUES('$name','$data','$testo')";
mysql_query($query) or die( "Errore nella query. Query non eseguita.");
mysql_close();
header("location: http://");}
mysql_connect(localhost,$username,$password);
@mysql_select_db($database)
   or die( "Impossibile selezionare il database dal G.");

$query="select * from bacheca";
$result= mysql_query($query);
$numfields = mysql_num_fields($result);

echo "<table>\n<tr>";
for ($i=0; $i < $numfields; $i++)
  {
   echo '<th>'.mysql_field_name($result, $i).'</th>';
   }
   echo "</tr>\n";
 
   while ($row = mysql_fetch_row($result))
  {
   echo '<tr><td><hr><b>'.implode($row,'</td><td><hr>')."</td></tr>\n";
  }
echo "</table>\n";
  ?>
</body>
</html>

Nessun commento:

Posta un commento