ciao. rigorosamente imho io farei così:
form.php (la form)
insert.php (inserimento nel database)
opzionalmente una pagina intermedia con la visualizzazione dei dati che ti interessano ma questo riguarderebbe gli utenti non te webmaster.
Provo a fare un esempio in codice.
P.S. Sto scrivendo a braccio quindi può essere che qualche sintassi sia errata ma comunque la logica è corretta se ho capito bene quello che ti serve
database.php
Codice PHP:
<?php
$dbuser = 'il_nome_del_tuo_utente_sql';
$dbpass = 'pass_del_utente_sql';
$dbhost = 'indirizzo_server_sql';
$dbname = 'nome_del_db';
// Adesso ci connettiamo al database usando username, host e password
$linkID = mysql_connect ( $dbuser, $dbpass, $dbhost ) or die ( 'Impossibile connettersi al database' );
// Adesso selezioniamo il database
mysql_select_db ( $dbname, $linkID);
?>
form.html
codice:
<html>
<head>
<title>Form</title>
</head>
<body>
I campi indicati con un asterisco sono necessari
<form method="post" action="http://www.mediciperidirittiumani.org/report.php">
<font face="Verdana, Geneva, sans-serif" size="2">Inserisci il tuo nome: * </font>
<input type="text" name="nome">
<font face="Verdana, Geneva, sans-serif" size="2">Inserisci la tua email: * </font>
<input type="text" name="email">
<font face="Verdana, Geneva, sans-serif" size="2">Scrivi i dati della persona a cui vuoi regalare la tessera: * </font>
<textarea name="testo" rows="5" cols="40"></textarea>
<input type="submit" value="Invia">
</form>
report.php
Codice PHP:
<?php
// Verifichiamo che i campi non siano vuoti
if ( $_POST['nome'] != '' && $_POST['email'] != '' && $_POST['testo'] != '' ) {
echo "Il tuo nome è: " . $_POST['nome'] . "
";
echo "La tua email é: " . $_POST['email'] . "
";
echo "Hai immesso il seguente testo: " . $_POST['testo'] . "
";
?>
<hr>
I dati inseriti sono corretti ? Se si premi invia altrimenti clicca sul pulsante back del browser
<form name='nome_form' action='insert.php' method='post'>
<input type=hidden value="<?php $_POST['nome']; ?>">
<input type=hidden value="<?php $_POST['email']; ?>">
<input type=hidden value="<?php $_POST['testo']; ?>">
<input type=submit>
<?php
} else {
echo "Alcuni campi risultano vuoti. Premi il pulsante back del browser";
}
?>
insert.php
Codice PHP:
<?php
// Includiamo la libreria di connessione al db
require_once 'database.php';
$nome = $_POST['nome'];
$mail = $_POST['mail'];
$testo = $_POST['testo'];
$nome = stripslashes('$nome');
$mail = stripslashes('$mail');
$testo = stripslashes('$testo');
$nome = mysql_real_escape_string('$nome');
$mail = mysql_real_escape_string('$mail');
$testo = mysql_real_escape_string('$testo');
$nome = htmlentities('$nome');
$mail = htmlentities('$mail');
$testo = htmlentities('$testo');
$sql = "INSERT INTO utenti (nome, mail, testo) VALUES ('$nome', '$mail', '$testo')";
$query = mysql_query ($sql, $linkID);
?>
A questo punto per gli utenti è finita. Non c'è altro da fare. Non rimane che la paginetta admin che consente a te di estrarre i dati del utente in base allo username (o altro dato a tua scelta).
admin.html
codice:
<html>
<head>
<title>Pagina di ricerca per il WebMaster</html>
</head>
<body>
Immetti il nome del utente da cercare e premi il pulsante invia
<form name = '' action = 'cerca.php' method = 'post'>
<input type = 'text' name = 'username'>
<input type = 'submit' value = 'cerca'>
</form>
</body>
</html>
cerca.php
Codice PHP:
<?php
require_once 'database.php';
$nomeUtente = $_POST['username']
$sql = "SELECT * FROM utenti WHERE nome = $username";
$query = mysql_query ( $sql, $linkID );
$dati = mysql_fetch_array ( $query );
echo "Stampa i dati del utente";
echo "Nome utente: " . $query[0] . "
";
echo "Email utente: " . $query[1] . "
";
echo "Testo: " . $query[2];
?>
database
codice:
CREATE TABLE IF NOT EXISTS `utenti` (
`nome` varchar(30) NOT NULL,
`mail` varchar(50) NOT NULL,
`test` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Ripeto che ho scritto a braccio quindi qualcosa potrebbe essere errata ma in linea di massima dovrebbe essere la soluzione che cerchi.
Ciao