Form PHP per inserire dati in database MYSQL
Ecco 2 pagine (una html e una php) per creare un semplice form per registrare i dati all'interno di un database mysql.
Quello di cui abbiamo bisogno è un database mysql, contenente per il nostro esempio una tabella di nome tabella_esempio contente i campi "name" e "address"
Il primo file si chiamerà form.html e altro non è che un semplice form che cattura i dati inseriti dall'utente al momento della digitazione:
Se i nostri articoli ti hanno aiutato, supportaci con una donazione.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>PAGINA CARICAMENTO DATI</title>
</head>
<body>
<table border="0">
<tr>
<td align="center">Inserisci i dati richiesti</td>
</tr>
<tr>
<td>
<table>
<form method="post" action="input.php">
<tr>
<td>Nome</td>
<td><input type="text" name="name" size="20">
</td>
</tr>
<tr>
<td>Indirizzo</td>
<td><input type="text" name="address" size="40">
</td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit"
name="submit" value="Sent"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Il secondo (input.php) file recupera i dati inseriti (nome e indirizzo) e li inserisce nelle 2 tabelle.
Se i nostri articoli ti hanno aiutato, supportaci con una donazione.
<?
//la stringa mysql_connect deve essere compilata con i dati relativi al proprio database
// HOST = IP server Mysql
// USER = Nome utente databse
// PASSWORD = Password utente databse
mysql_connect("HOST","USER","PASSWORD");//database connection
// Qui sotto al posto di NOME_DATABSE, inserite il nome del vostro DB
mysql_select_db("NOME_DATABASE");
//inserting data order
$toinsert = "INSERT INTO tabella_esempio
(nome, indirizzo)
VALUES
('$name',
'$address')";
//declare in the order variable
$result = mysql_query($toinsert); //order executes
if($result){
echo("<br>Inserimento avvenuto correttamente");
} else{
echo("<br>Inserimento non eseguito");
}
?>


