In questo tutorial vedremo come creare la nostra piccola applicazione php mysql per la ricerca di dati nel database.Iniziamo a creare un file chiamato search.php,abbiamo bisogno di creare una nuova connessione al database usando mysql_connect.
<?
$connection = mysql_connect('localhost', 'mysql_user', 'mysql_password') or die(mysql_error()); // Crea una nuova connessione.
mysql_select_db('database'); // Connette al database.
?>
Avendo cura di sostituire i dati con quelli corretti.Miglioriamo lo script, verificando che la stringa inserita non sia vuota:
<?
$connection = mysql_connect('localhost', 'mysql_user', 'mysql_password') or die(mysql_error()); // Creates a new connection to the mysql server.
mysql_select_db('database'); // Connects to the database.
if(!isset($_POST['search'])){ // If the form has not been submitted.
}elseif(isset($_POST['search'])){ // ElseIf the form has been submitted.
} // End ElseIf.
?>
Se la stringa di ricerca non è vuota, mostra i risultati , altrimenti in form di ricerca
<?
$connection = mysql_connect('localhost', 'mysql_user', 'mysql_password') or die(mysql_error()); // Creates a new connection to the mysql server.
mysql_select_db('database'); // Connects to the database.
if(!isset($_POST['search'])){ // If the form has not been submitted.
?>
<form method="POST">
Search: <input type="text" name="term" id="term" /><br/>
<input type="submit" name="search" id="search" value="Search" />
</form>
<?php
}elseif(isset($_POST['search'])){ // ElseIf the form has been submitted.
} // End ElseIf.
?>


























