RICAPITOLANDO...
read.php
codice:
<?php
$c = mysql_connect('localhost','root','xxxxxxx') or die(mysql_error());
mysql_select_db('lol', $c);
$id = (int)mysql_query("SELECT MAX(id) FROM commenti");
$n=rand(1,$id);
$query = mysql_query("SELECT * FROM commenti WHERE id=$n;");
$d = mysql_fetch_array($query);
$nome = $d['nome'];
$sito = $d['sito'];
$commento = $d['commento'];
print "Nome: $nome
\nSito: $sito
\nCommento: $commento
\n<hr>\n";
?>
insert.php
codice:
<form action='insert.php?go' method='POST'>
Nome: <input typE='text' name='nome'>
Sito: <input type='text' name='sito'>
Commento:
<textarea width='300' height='200' name='commento'></textarea>
<input type='submit' value='Inserisci'>
</form>
<?php
if(isset($_GET['go'])) {
if(isset($_POST['nome']) && isset($_POST['sito']) && isset($_POST['commento'])) {
$nome = $_POST['nome'];
$sito = $_POST['sito'];
$commento = $_POST['commento'];
$c = mysql_connect('localhost','root','xxxxxxx) or die(mysql_error());
mysql_select_db('lol', $c);
$query = mysql_query("INSERT INTO commenti (nome, sito, commento) VALUES ('$nome', '$sito', '$commento')");
if($query) {
print "COmmento inserito correttamente";
} else {
print "Errore durante l'inserimento del commento";
}
}
}
install.php
codice:
<?php
$c = mysql_connect('localhost','root','xxxxxxx') or die(mysql_error());
mysql_select_db('lol', $c);
$query = mysql_query("CREATE TABLE commenti (
id INT(5) AUTO_INCREMENT,
nome VARCHAR(255),
sito VARCHAR(255),
commento TEXT,
PRIMARY KEY(id)
)");
if($query) {
print "Guestbook creato con successo";
} else {
print "Errore durante la creazione del guestbook";
}
?>
QUESTO SCRIPT VEDE A RANDOM I COMMENTI INSERITI SUL DB MYSQL DAL FILE INSERT.PHP