J'ai sur mon portfolio, deux tables liées, une nommée infographisme contenant mes création et une nommée notesinfo contenant les notes que les visiteurs donnent à ces créations (voir http://lefebvresbook.monespace.net/info ... .php?ID=69 par exemple). Sur la page présentant les créations j'ai un bloc avec un effet lightbox pour donner une note ou modifier la note (si on a déjà voté) celui-ci fonctionne avec les adresses IP.
Lorsque je modifie une note juste après en avoir donné une (sans changer de page entre deux et quasiment uniquement dans ce cas), la page m'affiche Duplicate entry 'X' for key 1 (sachant que X correspond à l'ID)
voici le code du include (le include est sur la page infographisme-details.php, il contient la lightbox modifier la note si le visiteur a déjà noté, l'autre lightbox pour noter ne nous intéresse guère ici)
<?php
if (isset($_GET['ID'])) {
$IDgetted = $_GET['ID'];
}
?>
<!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>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" class="lightbox-bloccenter">
<tr>
<td>
<h1>Modifier ma note</h1>
<form action="scripts/editanote-action.php?ID=<?php echo($IDgetted)?>" method="POST" name="editanoteform">
<b>
<input type="hidden" name="MM_insert" value="editanoteform" />
Note :</b>
<select name="note" id="note">
<option value="1">01</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
</select> <b>/10</b>
<input type="submit" name="button" id="button" value="Envoyer" />
<input type="hidden" name="MM_update" value="editanoteform" />
</form>
<a href = "javascript:void(0)" onclick = "document.getElementById('lightbox-editanote').style.display='none';document.getElementById('fade-boxeditanote').style.display='none'">Fermer cette fenêtre</a>
</td>
</tr>
</table>
</body>
</html>
et voici le code du script editanote-action.php qui récupère les valeurs et en fais le traitement (page certainement à l'origine du problème) :<?php require_once('../Connections/portfoliodata.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
// fonction recuperation de l'ip du visiteur
function get_ip(){
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];}
elseif(isset($_SERVER['HTTP_CLIENT_IP'])){
$ip = $_SERVER['HTTP_CLIENT_IP'];}
else{ $ip = $_SERVER['REMOTE_ADDR'];}
return $ip;}$ip = get_ip();
// fin de fonction get_ip
if (isset($_GET['ID'])) {
$IDgetted = $_GET['ID'];
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "editanoteform")) {
$updateSQL = sprintf("UPDATE notesinfo SET note=%s, ID=%s, IDparentnote=%s, IP=%s WHERE IDparentnote=%s",
GetSQLValueString($_POST['note'], "int"),
GetSQLvalueString($IDgetted, "int"),
GetSQLValueString($IDgetted, "int"),
GetSQLValueString($ip, "text"),
GetSQLValueString($IDgetted, "int"));
mysql_select_db($database_portfoliodata, $portfoliodata);
$Result1 = mysql_query($updateSQL, $portfoliodata) or die(mysql_error());
$editGoTo = '../infographisme-details.php';
if (isset($_SERVER['QUERY_STRING'])) {
$editGoTo .= (strpos($editGoTo, '?')) ? "&" : "?";
$editGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $editGoTo));
}
?>
<!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>
</head>
<body>
</body>
</html>
Je remercie la communauté de bien vouloir m'aider à solutionner ce problème.