le 05/08/2009 à 15:56
billledouble
Bonjour,
J'ai consulté pendant plus de 4 heures différents forums mais n'ai pas trouvé de réponse à mon problème que je vous expose ci-après :
J'ai créé un formulaire me permettant d'insérer des éléments dans une base de données MYSQL.
J'ai un problème avec un des champs: un champ select multiple. Alors qu'en testant le formulaire je choisis avec CTRL deux valeurs et que j'envoie mon formulaire, aucune valeur n'est inscrite dans le champ correspondant 'aireint' de la base de données.
Merci d'avance de vos suggestions.
Bill
CODE DE MON FORMULAIRE REALISE AVEC DREAMWEAVER - VOIR CHAMP SELECT
<?php header('Content-Type: text/html; charset=utf-8'); ?>
<?php include_once("fckeditor/fckeditor.php") ; ?>
<?php require_once('Connections/gestion_if.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;
}
}
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;
}
}
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;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form_1")) {
$insertSQL = sprintf("INSERT INTO saisie_if (id_saisie, nomsousif, docs2, natsousif, pointeusif, pointnatsif, aireint) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id_saisie'], "int"),
GetSQLValueString($_POST['nomsousif'], "text"),
GetSQLValueString($_POST['docs2'], "text"),
GetSQLValueString($_POST['natsousif'], "text"),
GetSQLValueString($_POST['pointeusif'], "text"),
GetSQLValueString($_POST['pointnatsif'], "text"),
GetSQLValueString($_POST['aireint'], "text");
mysql_select_db($database_gestion_if, $gestion_if);
$Result1 = mysql_query($insertSQL, $gestion_if) or die(mysql_error());
$insertGoTo = "message_1.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_gestion_if, $gestion_if);
$query_lstaireint = "SELECT * FROM lstaireint";
$lstaireint = mysql_query($query_lstaireint, $gestion_if) or die(mysql_error());
$row_lstaireint = mysql_fetch_assoc($lstaireint);
$totalRows_lstaireint = mysql_num_rows($lstaireint);
?>
<!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>Saisie IF</title>
<style type="text/css">
<!--
.Style3 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: x-small; }
.Style4 {font-size: x-small}
.Style5 {font-family: Geneva, Arial, Helvetica, sans-serif}
-->
</style>
</head>
<body>
<label>
</label>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form_1" target="_self" id="form_1">
<table width="100%" border="0">
<tr>
<th width="28%" align="left" valign="top" scope="row"><span class="Style5">Niveau 1</span></th>
<td width="4%"> </td>
<td width="68%"> </td>
</tr>
<tr>
<th width="28%" align="left" valign="top" scope="row"> </th>
<td width="4%"> </td>
<td width="68%"> </td>
</tr>
<tr valign="baseline">
<th align="left" valign="top" class="Style3" scope="row">2.1 Nom du sous-programme</th>
<td align="left" valign="top" nowrap="nowrap"><img src="images/Info.png" alt="" width="25" height="25" /></td>
<td align="left" valign="top"><?php
$oFCKeditor = new FCKeditor('nomsousif') ;
$oFCKeditor->BasePath = './FCKeditor/';
//set the EnterMode to "br" (overwrites the default configuration from fckconfig.js)
$oFCKeditor->Config['EnterMode'] = 'br';
$oFCKeditor->Value = '' ;
$oFCKeditor->Create() ;
?></td>
</tr>
<tr valign="baseline">
<th align="left" valign="top" class="Style3" scope="row">2.2 Documents</th>
<td align="left" valign="top" nowrap="nowrap"><img src="images/Info.png" alt="" width="25" height="25" /></td>
<td align="left" valign="top"><?php
$oFCKeditor = new FCKeditor('docs2') ;
$oFCKeditor->BasePath = './FCKeditor/';
//set the EnterMode to "br" (overwrites the default configuration from fckconfig.js)
$oFCKeditor->Config['EnterMode'] = 'br';
$oFCKeditor->Value = '' ;
$oFCKeditor->Create() ;
?></td>
</tr>
<tr valign="baseline">
<th align="left" valign="top" class="Style3" scope="row">2.3 Nature du sous-programme</th>
<td align="left" valign="top" nowrap="nowrap"><img src="images/Info.png" alt="" width="25" height="25" /></td>
<td align="left" valign="top"><?php
$oFCKeditor = new FCKeditor('natsousif') ;
$oFCKeditor->BasePath = './FCKeditor/';
//set the EnterMode to "br" (overwrites the default configuration from fckconfig.js)
$oFCKeditor->Config['EnterMode'] = 'br';
$oFCKeditor->Value = '' ;
$oFCKeditor->Create() ;
?></td>
</tr>
<tr valign="baseline">
<th align="left" valign="top" class="Style3" scope="row">2.4 Point d’information européen</th>
<td align="left" valign="top" nowrap="nowrap"><img src="images/Info.png" alt="" width="25" height="25" /></td>
<td align="left" valign="top"><?php
$oFCKeditor = new FCKeditor('pointeusif') ;
$oFCKeditor->BasePath = './FCKeditor/';
//set the EnterMode to "br" (overwrites the default configuration from fckconfig.js)
$oFCKeditor->Config['EnterMode'] = 'br';
$oFCKeditor->Value = '' ;
$oFCKeditor->Create() ;
?></td>
</tr>
<tr valign="baseline">
<th align="left" valign="top" class="Style3" scope="row">2.5 Point d’information européen</th>
<td align="left" valign="top" nowrap="nowrap"><img src="images/Info.png" alt="" width="25" height="25" /></td>
<td align="left" valign="top"><?php
$oFCKeditor = new FCKeditor('pointnatsif') ;
$oFCKeditor->BasePath = './FCKeditor/';
//set the EnterMode to "br" (overwrites the default configuration from fckconfig.js)
$oFCKeditor->Config['EnterMode'] = 'br';
$oFCKeditor->Value = '' ;
$oFCKeditor->Create() ;
?></td>
</tr>
<tr valign="baseline">
<th align="left" valign="top" class="Style3" scope="row">2.6 Aire d’intervention</th>
<td align="left" valign="top" nowrap="nowrap"><img src="images/Info.png" alt="" width="25" height="25" /></td>
<td align="left" valign="top">
// CHAMP SELECTION EN QUESTION
<label>
<select name="aireint" size="4" id="aireint">
<?php
do {
?>
<option value="<?php echo $row_lstaireint['id_aireint']?>"><?php echo $row_lstaireint['aireint']?></option>
<?php
} while ($row_lstaireint = mysql_fetch_assoc($lstaireint));
$rows = mysql_num_rows($lstaireint);
if($rows > 0) {
mysql_data_seek($lstaireint, 0);
$row_lstaireint = mysql_fetch_assoc($lstaireint);
}
?>
</select>
</label></td>
</tr>
<tr valign="baseline">
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th align="left" valign="top" scope="row"></th>
<td> </td>
<td><input type="submit" name="Enregistrer" id="Enregistrer" value="Enregistrer" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form_1" />
</form>
</body>
</html>
<?php
mysql_free_result($lstaireint);
?>
J'ai consulté pendant plus de 4 heures différents forums mais n'ai pas trouvé de réponse à mon problème que je vous expose ci-après :
J'ai créé un formulaire me permettant d'insérer des éléments dans une base de données MYSQL.
J'ai un problème avec un des champs: un champ select multiple. Alors qu'en testant le formulaire je choisis avec CTRL deux valeurs et que j'envoie mon formulaire, aucune valeur n'est inscrite dans le champ correspondant 'aireint' de la base de données.
Merci d'avance de vos suggestions.
Bill
CODE DE MON FORMULAIRE REALISE AVEC DREAMWEAVER - VOIR CHAMP SELECT
<?php header('Content-Type: text/html; charset=utf-8'); ?>
<?php include_once("fckeditor/fckeditor.php") ; ?>
<?php require_once('Connections/gestion_if.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;
}
}
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;
}
}
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;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form_1")) {
$insertSQL = sprintf("INSERT INTO saisie_if (id_saisie, nomsousif, docs2, natsousif, pointeusif, pointnatsif, aireint) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id_saisie'], "int"),
GetSQLValueString($_POST['nomsousif'], "text"),
GetSQLValueString($_POST['docs2'], "text"),
GetSQLValueString($_POST['natsousif'], "text"),
GetSQLValueString($_POST['pointeusif'], "text"),
GetSQLValueString($_POST['pointnatsif'], "text"),
GetSQLValueString($_POST['aireint'], "text");
mysql_select_db($database_gestion_if, $gestion_if);
$Result1 = mysql_query($insertSQL, $gestion_if) or die(mysql_error());
$insertGoTo = "message_1.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_gestion_if, $gestion_if);
$query_lstaireint = "SELECT * FROM lstaireint";
$lstaireint = mysql_query($query_lstaireint, $gestion_if) or die(mysql_error());
$row_lstaireint = mysql_fetch_assoc($lstaireint);
$totalRows_lstaireint = mysql_num_rows($lstaireint);
?>
<!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>Saisie IF</title>
<style type="text/css">
<!--
.Style3 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: x-small; }
.Style4 {font-size: x-small}
.Style5 {font-family: Geneva, Arial, Helvetica, sans-serif}
-->
</style>
</head>
<body>
<label>
</label>
<form action="<?php echo $editFormAction; ?>" method="POST" name="form_1" target="_self" id="form_1">
<table width="100%" border="0">
<tr>
<th width="28%" align="left" valign="top" scope="row"><span class="Style5">Niveau 1</span></th>
<td width="4%"> </td>
<td width="68%"> </td>
</tr>
<tr>
<th width="28%" align="left" valign="top" scope="row"> </th>
<td width="4%"> </td>
<td width="68%"> </td>
</tr>
<tr valign="baseline">
<th align="left" valign="top" class="Style3" scope="row">2.1 Nom du sous-programme</th>
<td align="left" valign="top" nowrap="nowrap"><img src="images/Info.png" alt="" width="25" height="25" /></td>
<td align="left" valign="top"><?php
$oFCKeditor = new FCKeditor('nomsousif') ;
$oFCKeditor->BasePath = './FCKeditor/';
//set the EnterMode to "br" (overwrites the default configuration from fckconfig.js)
$oFCKeditor->Config['EnterMode'] = 'br';
$oFCKeditor->Value = '' ;
$oFCKeditor->Create() ;
?></td>
</tr>
<tr valign="baseline">
<th align="left" valign="top" class="Style3" scope="row">2.2 Documents</th>
<td align="left" valign="top" nowrap="nowrap"><img src="images/Info.png" alt="" width="25" height="25" /></td>
<td align="left" valign="top"><?php
$oFCKeditor = new FCKeditor('docs2') ;
$oFCKeditor->BasePath = './FCKeditor/';
//set the EnterMode to "br" (overwrites the default configuration from fckconfig.js)
$oFCKeditor->Config['EnterMode'] = 'br';
$oFCKeditor->Value = '' ;
$oFCKeditor->Create() ;
?></td>
</tr>
<tr valign="baseline">
<th align="left" valign="top" class="Style3" scope="row">2.3 Nature du sous-programme</th>
<td align="left" valign="top" nowrap="nowrap"><img src="images/Info.png" alt="" width="25" height="25" /></td>
<td align="left" valign="top"><?php
$oFCKeditor = new FCKeditor('natsousif') ;
$oFCKeditor->BasePath = './FCKeditor/';
//set the EnterMode to "br" (overwrites the default configuration from fckconfig.js)
$oFCKeditor->Config['EnterMode'] = 'br';
$oFCKeditor->Value = '' ;
$oFCKeditor->Create() ;
?></td>
</tr>
<tr valign="baseline">
<th align="left" valign="top" class="Style3" scope="row">2.4 Point d’information européen</th>
<td align="left" valign="top" nowrap="nowrap"><img src="images/Info.png" alt="" width="25" height="25" /></td>
<td align="left" valign="top"><?php
$oFCKeditor = new FCKeditor('pointeusif') ;
$oFCKeditor->BasePath = './FCKeditor/';
//set the EnterMode to "br" (overwrites the default configuration from fckconfig.js)
$oFCKeditor->Config['EnterMode'] = 'br';
$oFCKeditor->Value = '' ;
$oFCKeditor->Create() ;
?></td>
</tr>
<tr valign="baseline">
<th align="left" valign="top" class="Style3" scope="row">2.5 Point d’information européen</th>
<td align="left" valign="top" nowrap="nowrap"><img src="images/Info.png" alt="" width="25" height="25" /></td>
<td align="left" valign="top"><?php
$oFCKeditor = new FCKeditor('pointnatsif') ;
$oFCKeditor->BasePath = './FCKeditor/';
//set the EnterMode to "br" (overwrites the default configuration from fckconfig.js)
$oFCKeditor->Config['EnterMode'] = 'br';
$oFCKeditor->Value = '' ;
$oFCKeditor->Create() ;
?></td>
</tr>
<tr valign="baseline">
<th align="left" valign="top" class="Style3" scope="row">2.6 Aire d’intervention</th>
<td align="left" valign="top" nowrap="nowrap"><img src="images/Info.png" alt="" width="25" height="25" /></td>
<td align="left" valign="top">
// CHAMP SELECTION EN QUESTION
<label>
<select name="aireint" size="4" id="aireint">
<?php
do {
?>
<option value="<?php echo $row_lstaireint['id_aireint']?>"><?php echo $row_lstaireint['aireint']?></option>
<?php
} while ($row_lstaireint = mysql_fetch_assoc($lstaireint));
$rows = mysql_num_rows($lstaireint);
if($rows > 0) {
mysql_data_seek($lstaireint, 0);
$row_lstaireint = mysql_fetch_assoc($lstaireint);
}
?>
</select>
</label></td>
</tr>
<tr valign="baseline">
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<th align="left" valign="top" scope="row"></th>
<td> </td>
<td><input type="submit" name="Enregistrer" id="Enregistrer" value="Enregistrer" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form_1" />
</form>
</body>
</html>
<?php
mysql_free_result($lstaireint);
?>