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.
?>

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Reddit
  • scuttle
  • Smarking
  • Spurl
  • YahooMyWeb
  • DZone
  • Internetmedia
  • Snap2r
  • Technorati

Letto:1738 volte

Correlati

    No related posts

Leave a Reply

web tracker