Contrôler que les valeurs n'existent pas dans la tables
Posté : 06 janv. 2006, 00:44
Salut,
J'ai fait un petit script pour insérer des enregistrements dans une table mais au cas où (je perd mon latin) comment être certain que les valeurs ne sont pas existantes?
Un peu plus d'explication: je dois insérer plusieurs paramétres pour identifier une personne mais elle pourrait malgré tout avoir le même nom et prénom ... c'est pour cela que j'ai inclus en plus la date de naissance, y'aura moins de risque que les 3 concordes!
Voici mon code:
Merci
J'ai fait un petit script pour insérer des enregistrements dans une table mais au cas où (je perd mon latin) comment être certain que les valeurs ne sont pas existantes?
Un peu plus d'explication: je dois insérer plusieurs paramétres pour identifier une personne mais elle pourrait malgré tout avoir le même nom et prénom ... c'est pour cela que j'ai inclus en plus la date de naissance, y'aura moins de risque que les 3 concordes!
Voici mon code:
<?php require_once('../../Connections/kainb_database.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO acrho_participant (nom, prenom, date_naissance, sexe) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['nom'], "text"),
GetSQLValueString($_POST['prenom'], "text"),
GetSQLValueString($_POST['naissance'], "date"),
GetSQLValueString($_POST['sexe_part'], "text"));
mysql_select_db($database_kainb_database, $kainb_database);
$Result1 = mysql_query($insertSQL, $kainb_database) or die(mysql_error());
$insertGoTo = "table_participants.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_kainb_database, $kainb_database);
$query_news_part = "SELECT * FROM acrho_participant";
$news_part = mysql_query($query_news_part, $kainb_database) or die(mysql_error());
$row_news_part = mysql_fetch_assoc($news_part);
$totalRows_news_part = mysql_num_rows($news_part);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Enregistrement des participants</title>
</head>
<body>
<table width="702" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="46" height="27"> </td>
<td width="624"> </td>
<td width="32"> </td>
</tr>
<tr>
<td height="195"> </td>
<td valign="top"> <form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>Nom du coureur </td>
<td><input name="nom" type="text" id="nom" maxlength="45"></td>
</tr>
<tr>
<td>Prénom du coureur </td>
<td><input name="prenom" type="text" id="prenom" maxlength="45"></td>
</tr>
<tr>
<td height="54">Sexe</td>
<td><p>
<label>
<input name="sexe_part" type="radio" value="H" checked>
Homme</label>
<br>
<label>
<input name="sexe_part" type="radio" value="D">
Femme</label>
<br>
</p></td>
</tr>
<tr>
<td>Date de naissance </td>
<td><input name="naissance" type="text" id="naissance" value="AAAA-MM-JJ" maxlength="10"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Envoyer">
<input type="reset" name="Submit" value="Réinitialiser"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form></td>
<td> </td>
</tr>
<tr>
<td height="20"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="125"></td>
<td valign="top"><!--DWLayoutEmptyCell--> </td>
<td></td>
</tr>
<tr>
<td height="49"></td>
<td> </td>
<td></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($news_part);
?>
Si quelqu'un peut m'aider?Merci