Salut,
Je laisse un exemple (non testé parce que je ne dispose pas de php là tout de suite).
Ca suppose d'avoir :
- un fichier de connexion à la bdd,
- une table nommée "table" avec deux champs : "id" en auto_increment et "data",
- et au moins un premier enregistrement dans cette table.
<?php
header('Content-type: text/html; charset=utf-8');
require_once 'connect.php';
if(empty($_POST['data']))
{
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Exemple</title>
<style type="text/css"><!--
@media screen, projection
{
body
{
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 80%;
}
.select a
{
color: black;
text-decoration: none;
font-size: 1em;
}
.select textarea
{
font-family: Verdana, Arial, Helvetica, sans-serif;
padding: 0;
border: 0;
margin: 0;
overflow: visible;
font-size: 1em;
width: 100%;
}
}
--></style>
<script type="text/javascript"><!--
var oO =
{
bXHRSupport: (typeof XMLHttpRequest != "undefined"),
bActiveXSupport: (window.ActiveXObject),
aMSXML: ["Microsoft.XMLHTTP",
"MSXML2.XMLHTTP", "MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP.4.0", " MSXML2.XMLHTTP.5.0",
"MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.7.0"],
createXHR: function()
{
var iI;
if(oO.bXHRSupport)
return new XMLHttpRequest;
else if(oO.bActiveXSupport)
{
iI = oO.aMSXML.length;
do
{
try
{
return new ActiveXObject( oO.aMSXML[--iI]);
}
catch(oError) { }
}
while(iI > 0);
throw new Error("L'objet XHR n'a pas été créé.");
}
},
getXHR: function(oReq)
{
try
{
var oXHR;
oXHR = oO.createXHR();
oO.oReq = oReq;
oXHR.open (oO.oReq['method'], oO.oReq['url'], true);
oXHR.temp = setTimeout(
function()
{
oXHR.abort();
return alert('Le serveur met trop de temps à répondre !');
},
3000
);
oXHR.onreadystatechange = function()
{
if(oXHR.readyState === 4)
if(oXHR.status && /200|304/.test( oXHR.status))
{
clearTimeout(oXHR.temp);
oO.oReq['response'] = oXHR.responseText;
if( oO.oReq['callback'])
(oO.oReq['callback'])();
}
}
oXHR.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
if(oO.oReq['method'] === 'post')
oXHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
oO.oReq['method'] === 'get' ?
oXHR.send(null):
oXHR.send(oO.oReq['param']);
return true;
}
catch(e)
{
return false;
}
},
connect: function(oElem, sEvType, fn, bCapture)
{
return document.addEventListener ?
oElem.addEventListener(sEvType, fn, bCapture):
oElem.attachEvent ?
oElem.attachEvent('on' + sEvType, fn):
false;
},
cancelClick: function(e)
{
if(e && e.stopPropagation && e.preventDefault )
{
e.stopPropagation();
e.preventDefault();
}
else if(e && window.event)
{
window.event.cancelBubble = true;
window.event.returnValue = false;
}
return false;
},
getSource: function(e)
{
return e ?
e.target || e.srcElement:
false;
},
affectSelect: function(oEl)
{
oEl.innerHTML = '<a href="#select">' + oEl.innerHTML + '</a>';
return oO.connect(oEl.firstChild, 'click', oO.select, false);
},
reaffectSelect: function(e)
{
var oSrc, oParent, sValue;
oSrc = oO.getSource(e);
oParent = oSrc.parentNode;
sValue = 'data=' + oSrc.value;
return oO.getXHR(
{
'cible': oParent,
'method': 'post',
'url': document.location,
'param': sValue,
'callback': oO.majTxt
}
);
},
majTxt: function()
{
oO.oReq['cible'].innerHTML = '<a href="#select">' + oO.oReq ['response'] + '</a>';
return oO.connect(oO.oReq['cible'].firstChild, 'click', oO.select, false);
},
select: function(e)
{
var oSrc, oParent;
oO.cancelClick(e);
oSrc = oO.getSource(e);
oParent = oSrc.parentNode;
oParent.innerHTML = '<textarea rows="" cols="">' + oSrc.innerHTML + '</textarea>';
oParent.firstChild.select();
return oO.connect(oParent.firstChild, 'blur', oO.reaffectSelect, false);
},
init: function()
{
var aPs, iP;
aPs = document.getElementsByTagName('p');
iP = aPs.length;
do
{
if(aPs[--iP].className === 'select')
oO.affectSelect(aPs[iP]);
}
while(iP > 0);
return true;
}
};
oO.connect(window, 'load', oO.init, false);
//--></script>
</head>
<body>
<p class="select">
<?php
}
if(!empty($_POST['data']))
{
if(get_magic_quotes_gpc() === 1)
$_POST['data'] = stripslashes($_POST['data']);
$data = mysql_escape_string($_POST['data']);
$requete = "INSERT INTO table(data) VALUES('$data')";
mysql_query($requete) or die('Erreur dans la requête : ' . $requete . '<br>Avec l\'erreur : ' . mysql_error());
}
$requete = "SELECT data FROM table ORDER BY id DESC LIMIT 1";
$select = mysql_query($requete) or die('Erreur dans la requête : ' . $requete . '<br>Avec l\'erreur : ' . mysql_error());
while($result = mysql_fetch_array($select))
echo htmlentities(stripslashes(nl2br($result['data'])));
mysql_close();
if(empty($_POST['data']))
{
?>
</p>
</body>
</html>
<?php
}
?>
A adapter selon les besoins.