auto-complété add if not existe
bonjour a tous, j'ai un problèmes avec mon script d'auto-compléter, jusqu'à maintenant il marche bien quand on commence à écrire le non d'une ville qu'il reconnait il la complète sauf que je cherche à intégrer un morceau de code d'insertion pour qu'il puisse ajouter une ville s'il la reconnait pas
et merci
voici la page index.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>AUSU DEMO | jQuery-Ajax Auto Suggest Plugin</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<style>
div {margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size:12px; }
.ausu-suggest {width: 280px;}
#wrapper {margin-left: auto; position: relative; margin-right: auto; margin-top:75px ;width: 600px;}
h3 {font-size: 11px; text-align: center;}
span {font-size: 11px; font-weight: bold}
a:link {color: #F06;text-decoration: none;}
a:visited {text-decoration: none;color: #F06;}
a:hover {text-decoration: underline;color: #09F;}
a:active {text-decoration: none;color: #09F;}
</style>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.ausu-autosuggest.min.js"></script>
<script>
$(document).ready(function() {
$.fn.autosugguest({
className: 'ausu-suggest',
methodType: 'POST',
minChars: 2,
rtnIDs: true,
dataFile: 'data.php'
});
});
</script>
</head>
<body>
<div id="wrapper">
<form action="index.php" method="get">
<div class="ausu-suggest">
<input type="text" size="25" value="" name="countries" id="countries" autocomplete="off" />
<input type="text" size="4" value="" name="countriesID" id="countriesid" autocomplete="off" disabled="disabled" />
<h3>Ville</h3>
</div>
<div class="ausu-suggest">
<input type="text" size="25" value="" name="deplome" id="deplome" autocomplete="off" />
<input type="text" size="4" value="" name="categoriesID" id="categoriesID" autocomplete="off" disabled="disabled" />
<input name="go" type="submit" value="go" style="width:1px;height:1px" />
<h3>Doing what?</h3>
</div>
</form>
</div>
</body>
</html> |
et data.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
<?php
/*
* AUSU jQuery-Ajax Autosuggest v1.0
* Demo of a simple server-side request handler
* Note: This is a very cumbersome code and should only be used as an example
*/
# Establish DB Connection
$con = mysql_connect(":/Applications/MAMP/tmp/mysql/mysql.sock","root","rootroot");
if (!$con){ die('Could not connect: ' . mysql_error()); }
mysql_select_db("gestion_personel", $con);
# Assign local variables
$id = @$_POST['id']; // The id of the input that submitted the request.
$data = @$_POST['data']; // The value of the textbox.
if ($id && $data)
{
if ($id=='countries')
{
$query = "SELECT id_ville,libelle_ville
FROM t_ville
WHERE libelle_ville LIKE '%$data%'
LIMIT 5";
$result = mysql_query($query);
$dataList = array();
while ($row = mysql_fetch_array($result))
{
$toReturn = $row['libelle_ville'];
$dataList[] = '<li id="' .$row['id_ville'] . '"><a href="#">' . htmlentities($toReturn) . '</a></li>';
}
if (count($dataList)>=1)
{
$dataOutput = join("\r\n", $dataList);
echo $dataOutput;
}
else
{
echo '<li><a href="#">No Results </a></li>';
}
}
}
else
{
echo 'Request Error';
}
/* $query_insert = "INSERT INTO
t_ville
(libelle_ville )
VALUES
('".mysql_real_escape_string(@trim($data))."')";
$result_insert = mysql_query($query_insert)or die (mysql_error());
*/
?> |