Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PHP & MySQL
PHP & MySQL Forum d'entraide sur les fonctions MySQL avec PHP. Avant de poster -> FAQ MySQL, Cours MySQL et Sources MySQL. Pour les questions concernant le moteur MySQL plutôt que les fonctions PHP, merci d'utiliser le forum MySQL.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 28/01/2012, 13h01   #1
Invité de passage
 
Inscription : novembre 2011
Messages : 20
Détails du profil
Informations forums :
Inscription : novembre 2011
Messages : 20
Points : 3
Points : 3
Par défaut Pb d'insertion datapicker

Bonjour,

J'ai realise un formulaire en Php dans lequel un champ est une date d'ou ma volonte d'inserer un datapicker mais lors de mes test lors de clique sur le bouton d'envoi la base de données est incrementée mais le la date reste 0000-00-00 alors que les autres champs sont correctement remplis.

Voici mon code :
Citation:
<?php require_once('Connections/cnxTestDate1.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;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ajout-vacations")) {
$insertSQL = sprintf("INSERT INTO vacation (num_vacation, nom_vac, num_iade, num_bloc, dat) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['numero_vac'], "int"),
GetSQLValueString($_POST['libelle_vac'], "text"),
GetSQLValueString($_POST['num_iade'], "int"),
GetSQLValueString($_POST['num_bloc'], "int"),
GetSQLValueString($_POST['dat'], "date"));

mysql_select_db($database_cnxTestDate1, $cnxTestDate1);
$Result1 = mysql_query($insertSQL, $cnxTestDate1) or die(mysql_error());
}

mysql_select_db($database_cnxTestDate1, $cnxTestDate1);
$query_rsIade = "SELECT * FROM iade";
$rsIade = mysql_query($query_rsIade, $cnxTestDate1) or die(mysql_error());
$row_rsIade = mysql_fetch_assoc($rsIade);
$totalRows_rsIade = mysql_num_rows($rsIade);

mysql_select_db($database_cnxTestDate1, $cnxTestDate1);
$query_rsbloc = "SELECT * FROM bloc";
$rsbloc = mysql_query($query_rsbloc, $cnxTestDate1) or die(mysql_error());
$row_rsbloc = mysql_fetch_assoc($rsbloc);
$totalRows_rsbloc = mysql_num_rows($rsbloc);
?>
<!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>Document sans titre</title>

<link type="text/css" href="css/style.css" rel="stylesheet" />
<link type="text/css" href="css/cupertino/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="js/ui.datepicker-fr.js"></script>

<script type="text/javascript">
$(document).ready(function() {
$("#datepicker").datepicker();
});
</script>

<style type="text/css">
#ui-datepicker-div{ font-size: 80%; }
</style>

</head>

<body>
<p>&nbsp;</p>
<form id="ajout-vacations" name="ajout-vacations" method="POST" action="<?php echo $editFormAction; ?>">
<p>
<label for="numero_vac">Numero vacation :</label>
<input type="text" name="numero_vac" id="numero_vac" accesskey="n" tabindex="1" />
</p>
<p>
<label for="libelle_vac">Nom vacation :</label>
<input type="text" name="libelle_vac" id="libelle_vac" accesskey="l" tabindex="2" />
</p>
<p>
<label for="num_iade">Numero IADE :</label>
<select name="num_iade" id="num_iade" accesskey="i" tabindex="3">
<?php
do {
?>
<option value="<?php echo $row_rsIade['num_iade']?>"><?php echo $row_rsIade['num_iade']?></option>
<?php
} while ($row_rsIade = mysql_fetch_assoc($rsIade));
$rows = mysql_num_rows($rsIade);
if($rows > 0) {
mysql_data_seek($rsIade, 0);
$row_rsIade = mysql_fetch_assoc($rsIade);
}
?>
</select>
</p>
<p>
<label for="num_bloc">Numero Bloc :</label>
<select name="num_bloc" id="num_bloc" accesskey="b" tabindex="4">
<?php
do {
?>
<option value="<?php echo $row_rsbloc['num_bloc']?>"><?php echo $row_rsbloc['num_bloc']?></option>
<?php
} while ($row_rsbloc = mysql_fetch_assoc($rsbloc));
$rows = mysql_num_rows($rsbloc);
if($rows > 0) {
mysql_data_seek($rsbloc, 0);
$row_rsbloc = mysql_fetch_assoc($rsbloc);
}
?>
</select>
</p>
<p>
<label for="dat">Date :</label>

<input type="text" id="datepicker" name="datepicker" />
</p>
<p>&nbsp;</p>
<p>
<input type="submit" name="envoi" id="envoi" value="Ajout d'une vacation" accesskey="e" tabindex="6" />
</p>
<p>&nbsp;</p>
<input type="hidden" name="MM_insert" value="ajout-vacations" />
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($rsIade);

mysql_free_result($rsbloc);
?>
La copie du fichier pour creer la base
Citation:
-- phpMyAdmin SQL Dump
-- version 3.3.9
-- http://www.phpmyadmin.net
--
-- Serveur: localhost
-- Généré le : Dim 06 Novembre 2011 à 21:09
-- Version du serveur: 5.5.8
-- Version de PHP: 5.3.1

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Base de données: `test_date_1`
--
CREATE DATABASE `test_date_1` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
USE `test_date_1`;

-- --------------------------------------------------------

--
-- Structure de la table `bloc`
--

DROP TABLE IF EXISTS `bloc`;
CREATE TABLE IF NOT EXISTS `bloc` (
`num_bloc` int(4) NOT NULL,
`nom_bloc` varchar(255) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Contenu de la table `bloc`
--

INSERT INTO `bloc` (`num_bloc`, `nom_bloc`) VALUES
(1, 'BMC 11'),
(2, 'BMC 12'),
(3, 'BMC 13'),
(4, 'BMC 14'),
(5, 'BMC 15'),
(6, 'BMC 16'),
(7, 'BMC 17'),
(8, 'BMC 18'),
(9, 'BMC 19'),
(10, 'BMC 20');

-- --------------------------------------------------------

--
-- Structure de la table `iade`
--

DROP TABLE IF EXISTS `iade`;
CREATE TABLE IF NOT EXISTS `iade` (
`num_iade` int(4) NOT NULL,
`nom_iade` varchar(255) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Contenu de la table `iade`
--

INSERT INTO `iade` (`num_iade`, `nom_iade`) VALUES
(1, 'AMIOT'),
(2, 'BISSON'),
(3, 'BOUTET'),
(4, 'CANU'),
(5, 'CARON'),
(6, 'COURDY'),
(7, 'DUMOND'),
(8, 'DUROT'),
(9, 'FOUQUET'),
(10, 'GAYEZ');

-- --------------------------------------------------------

--
-- Structure de la table `vacation`
--

DROP TABLE IF EXISTS `vacation`;
CREATE TABLE IF NOT EXISTS `vacation` (
`num_vacation` int(4) NOT NULL,
`nom_vac` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`num_iade` int(4) NOT NULL,
`num_bloc` int(4) NOT NULL,
`dat` date DEFAULT '0000-00-00'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Contenu de la table `vacation`
--

INSERT INTO `vacation` (`num_vacation`, `nom_vac`, `num_iade`, `num_bloc`, `dat`) VALUES
(1, 'vac1', 1, 2, '2011-11-01'),
(2, 'vac2', 1, 2, '2011-11-02');
La copie du fichier de connexion
Citation:
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_cnxTestDate1 = "localhost";
$database_cnxTestDate1 = "test_date_1";
$username_cnxTestDate1 = "raphael";
$password_cnxTestDate1 = "azer1234";
$cnxTestDate1 = mysql_pconnect($hostname_cnxTestDate1, $username_cnxTestDate1, $password_cnxTestDate1) or trigger_error(mysql_error(),E_USER_ERROR);
?>
Auriez vous une idée de l'erreur que j'ai faite ? Un conseil ? une idée ? SVP Merci

Raphael
Raphaelphp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 13h06   #2
Membre expérimenté
 
Avatar de buggen25
 
Inscription : août 2008
Messages : 510
Détails du profil
Informations forums :
Inscription : août 2008
Messages : 510
Points : 595
Points : 595
Par défaut Probleme de format date

Bonjour,
Je crois que le probleme vient du format de la date
Cordialement
__________________
If you type Google into Google, you Can break the internet" - The IT Crowd
buggen25 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 14h00   #3
Invité de passage
 
Inscription : novembre 2011
Messages : 20
Détails du profil
Informations forums :
Inscription : novembre 2011
Messages : 20
Points : 3
Points : 3
Par défaut Pb datapicker

Bonjour,

Merci pour cette reponse mais est ce que vous pourriez etes plus precis ? SVP Merci

Raphael
Raphaelphp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 14h12   #4
Membre expérimenté
 
Avatar de buggen25
 
Inscription : août 2008
Messages : 510
Détails du profil
Informations forums :
Inscription : août 2008
Messages : 510
Points : 595
Points : 595
Re:
Cette ligne me semble suspecte :
Code :
GetSQLValueString($_POST['dat'], "date"));
j'ai parcouru ton code source, mais je n'ai pas trouvé un champ qui possede l'attribut nom 'dat', ne serait ce pas "datepicker" ?
Code :
<input type="text" id="datepicker" name="datepicker" />
Si c'est le cas faut remplacer
Code :
GetSQLValueString($_POST['datepicker'], "date"));
Cordialement
__________________
If you type Google into Google, you Can break the internet" - The IT Crowd
buggen25 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 15h23   #5
Invité de passage
 
Inscription : novembre 2011
Messages : 20
Détails du profil
Informations forums :
Inscription : novembre 2011
Messages : 20
Points : 3
Points : 3
Par défaut Pb datapicker

Salut,

merci

grace a ta reponse, je vois apparaitre le Datapicker quand je clique sur le champs mais quand je valide (apres avoir selectionne une date, je la vois apparaitre dans le champs et le datapicker disparait) la base s'increment d'un nouvel enregistrement mais la date enregistree reste 0000-00-00.

Aurais tu une nouvelle brillante idee ?

SVP Merci

Raphael
Raphaelphp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 15h53   #6
Membre expérimenté
 
Avatar de buggen25
 
Inscription : août 2008
Messages : 510
Détails du profil
Informations forums :
Inscription : août 2008
Messages : 510
Points : 595
Points : 595
Re:
Je ne sais pas si ça va fonctionner, mais faut verifier le format de la date sur ton champ de saisie de la date "2012-01-28", Ensuite utiliser la fonction strtotime("2012-01-28") avant l'insertion dans la base

Faut mettre le format de la date soi en ISO c'est a dire yyyy-mm-dd, une fois que t'as ta date a partir de ton datepicker faut la découper, l'assembler et la transformer au format yyyy-mm-dd (exemple 2012-01-28), pour ensuite l'inserer dans la base de donnée

Essaye ça avec le fragmeent de code suivant :
Code :
1
2
3
4
5
6
7
8
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ajout-vacations")) {
 $insertSQL = sprintf("INSERT INTO vacation (num_vacation, nom_vac, num_iade, num_bloc, dat) VALUES (%s, %s, %s, %s, NOW())",
 GetSQLValueString($_POST['numero_vac'], "int"),
 GetSQLValueString($_POST['libelle_vac'], "text"),
 GetSQLValueString($_POST['num_iade'], "int"),
 GetSQLValueString($_POST['num_bloc'], "int")
 //GetSQLValueString($_POST['dat'], "date"))
__________________
If you type Google into Google, you Can break the internet" - The IT Crowd
buggen25 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 16h13   #7
Invité de passage
 
Inscription : novembre 2011
Messages : 20
Détails du profil
Informations forums :
Inscription : novembre 2011
Messages : 20
Points : 3
Points : 3
Par défaut Probleme de code (suite)

Salut,

Merci de l'aide.

Question du debutant que je suis où placer ton fragment de code ?

SVP Merci

Raphael
Raphaelphp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 16h27   #8
Membre expérimenté
 
Avatar de buggen25
 
Inscription : août 2008
Messages : 510
Détails du profil
Informations forums :
Inscription : août 2008
Messages : 510
Points : 595
Points : 595
Re:
J'ai testé le code chez moi il fonctionne, une petite question avant de cliquer sur le bouton "ajouter une vacation" tu peux me donner ce que le champ date contient ?
__________________
If you type Google into Google, you Can break the internet" - The IT Crowd
buggen25 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 16h35   #9
Invité de passage
 
Inscription : novembre 2011
Messages : 20
Détails du profil
Informations forums :
Inscription : novembre 2011
Messages : 20
Points : 3
Points : 3
Par défaut Pb Datepicker -suite

il contient 28-01-2012

cela t'aide ?

Raphael
Raphaelphp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 16h46   #10
Membre expérimenté
 
Avatar de buggen25
 
Inscription : août 2008
Messages : 510
Détails du profil
Informations forums :
Inscription : août 2008
Messages : 510
Points : 595
Points : 595
Re :
Eureka !! La on voit d'ou provient le probleme le format d'insertion n'est pas correcte le format de la date est
28-01-2012 = jj-mm-aaaa

Mais avant l'insertion dans la base de donnée faut qu'il soit de la forme
aaaa-mm-jj c'est a dire 2012-01-28.

Remplace 28-01-2012 par 2012-01-28 dans le champ de saisie pour tester si ça fontionne cordialement
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php require_once('Connections/cnxTestDate1.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;
 }
 }

 $editFormAction = $_SERVER['PHP_SELF'];
 if (isset($_SERVER['QUERY_STRING'])) {
 $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
 }
 $date = implode('-', array_reverse( explode('-',$_POST['datepicker']) ) ) ;
 if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ajout-vacations")) {
 $insertSQL = sprintf("INSERT INTO vacation (num_vacation, nom_vac, num_iade, num_bloc, dat) VALUES (%s, %s, %s, %s, %s)",
 GetSQLValueString($_POST['numero_vac'], "int"),
 GetSQLValueString($_POST['libelle_vac'], "text"),
 GetSQLValueString($_POST['num_iade'], "int"),
 GetSQLValueString($_POST['num_bloc'], "int"),
 GetSQLValueString($date, "date"));

 mysql_select_db($database_cnxTestDate1, $cnxTestDate1);
 $Result1 = mysql_query($insertSQL, $cnxTestDate1) or die(mysql_error());
 }

 mysql_select_db($database_cnxTestDate1, $cnxTestDate1);
 $query_rsIade = "SELECT * FROM iade";
 $rsIade = mysql_query($query_rsIade, $cnxTestDate1) or die(mysql_error());
 $row_rsIade = mysql_fetch_assoc($rsIade);
 $totalRows_rsIade = mysql_num_rows($rsIade);

 mysql_select_db($database_cnxTestDate1, $cnxTestDate1);
 $query_rsbloc = "SELECT * FROM bloc";
 $rsbloc = mysql_query($query_rsbloc, $cnxTestDate1) or die(mysql_error());
 $row_rsbloc = mysql_fetch_assoc($rsbloc);
 $totalRows_rsbloc = mysql_num_rows($rsbloc);
 ?>
 <!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>Document sans titre</title>

 <link type="text/css" href="css/style.css" rel="stylesheet" />
 <link type="text/css" href="css/cupertino/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
 <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
 <script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
 <script type="text/javascript" src="js/ui.datepicker-fr.js"></script>

 <script type="text/javascript">
 $(document).ready(function() {
 $("#datepicker").datepicker();
 }); 
 </script> 

 <style type="text/css">
 #ui-datepicker-div{ font-size: 80%; }
 </style>

 </head>

 <body>
 <p>&nbsp;</p>
 <form id="ajout-vacations" name="ajout-vacations" method="POST" action="<?php echo $editFormAction; ?>">
 <p>
 <label for="numero_vac">Numero vacation :</label>
 <input type="text" name="numero_vac" id="numero_vac" accesskey="n" tabindex="1" />
 </p>
 <p>
 <label for="libelle_vac">Nom vacation :</label>
 <input type="text" name="libelle_vac" id="libelle_vac" accesskey="l" tabindex="2" />
 </p>
 <p>
 <label for="num_iade">Numero IADE :</label>
 <select name="num_iade" id="num_iade" accesskey="i" tabindex="3">
 <?php
 do { 
 ?>
 <option value="<?php echo $row_rsIade['num_iade']?>"><?php echo $row_rsIade['num_iade']?></option>
 <?php
 } while ($row_rsIade = mysql_fetch_assoc($rsIade));
 $rows = mysql_num_rows($rsIade);
 if($rows > 0) {
 mysql_data_seek($rsIade, 0);
 $row_rsIade = mysql_fetch_assoc($rsIade);
 }
 ?>
 </select>
 </p>
 <p>
 <label for="num_bloc">Numero Bloc :</label>
 <select name="num_bloc" id="num_bloc" accesskey="b" tabindex="4">
 <?php
 do { 
 ?>
 <option value="<?php echo $row_rsbloc['num_bloc']?>"><?php echo $row_rsbloc['num_bloc']?></option>
 <?php
 } while ($row_rsbloc = mysql_fetch_assoc($rsbloc));
 $rows = mysql_num_rows($rsbloc);
 if($rows > 0) {
 mysql_data_seek($rsbloc, 0);
 $row_rsbloc = mysql_fetch_assoc($rsbloc);
 }
 ?>
 </select>
 </p>
 <p>
 <label for="dat">Date :</label>

 <input type="text" id="datepicker" name="datepicker" />
 </p>
 <p>&nbsp;</p>
 <p>
 <input type="submit" name="envoi" id="envoi" value="Ajout d'une vacation" accesskey="e" tabindex="6" />
 </p>
 <p>&nbsp;</p>
 <input type="hidden" name="MM_insert" value="ajout-vacations" />
 </form>
 <p>&nbsp;</p>
 </body>
 </html>
 <?php
 mysql_free_result($rsIade);

 mysql_free_result($rsbloc);
 ?>
Normalement le code ci dessus devrait fonctionner grace a la ligne que j'ai rajouté en vert qui transforme le format date jj-mm-aaaa en aaaa-mm-jj
__________________
If you type Google into Google, you Can break the internet" - The IT Crowd
buggen25 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 16h54   #11
Invité de passage
 
Inscription : novembre 2011
Messages : 20
Détails du profil
Informations forums :
Inscription : novembre 2011
Messages : 20
Points : 3
Points : 3
Par défaut Pb Datepicker -suite

Cela fonctionne !!!

Donc il me faut inverser le format : je sais pas faire encore une nouvelle interrogation pour moi.

La base de donnees est codee en
utf8-unicode-ci

est cela la cause ??

Y a t il un remede "docteur" ?

SVP Merci

Raphael
Raphaelphp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 17h04   #12
Membre expérimenté
 
Avatar de buggen25
 
Inscription : août 2008
Messages : 510
Détails du profil
Informations forums :
Inscription : août 2008
Messages : 510
Points : 595
Points : 595
Re:
Non ça n'a rien avoir avec l'encodage UTF-8 ça c'est une autre histoire ton encodage est presque parfait c'est juste un probleme de date, avant d'inserer une date dans la base il faut qu'elle soit du format aaaa-mm-jj et rien d'autre ne pourrait fonctionner donc pour se faire, faut inverser la chaine de caractères
Exemple :
Code :
1
2
3
4
 
$date ="12-01-2012";
$date = implode('-', array_reverse( explode('-',"12-01-2012" ) ) ;
// La on peut inserer dans la base de donnée
Mais bon on peut utiliser d'autres méthodes
Cordialement
__________________
If you type Google into Google, you Can break the internet" - The IT Crowd
buggen25 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 17h09   #13
Membre expérimenté
 
Avatar de buggen25
 
Inscription : août 2008
Messages : 510
Détails du profil
Informations forums :
Inscription : août 2008
Messages : 510
Points : 595
Points : 595
Re :
Eureka !! La on voit d'ou provient le probleme le format d'insertion n'est pas correcte le format de la date est
28-01-2012 = jj-mm-aaaa

Mais avant l'insertion dans la base de donnée faut qu'il soit de la forme
aaaa-mm-jj c'est a dire 2012-01-28.

Remplace 28-01-2012 par 2012-01-28 dans le champ de saisie pour tester si ça fontionne cordialement
__________________
If you type Google into Google, you Can break the internet" - The IT Crowd
buggen25 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 17h22   #14
Invité de passage
 
Inscription : novembre 2011
Messages : 20
Détails du profil
Informations forums :
Inscription : novembre 2011
Messages : 20
Points : 3
Points : 3
Par défaut Pb Datepicker -suite

Je place ton extrait de code

Citation:
$date ="12-01-2012";
$date = implode('-', array_reverse( explode('-',"12-01-2012" ) ) ;
// La on peut inserer dans la base de donnée
Où dans mon code source ?SVP Merci

Mon code actuel :

Citation:
<?php require_once('Connections/cnxTestDate1.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;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ajout-vacations")) {
$insertSQL = sprintf("INSERT INTO vacation (num_vacation, nom_vac, num_iade, num_bloc, dat) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['numero_vac'], "int"),
GetSQLValueString($_POST['libelle_vac'], "text"),
GetSQLValueString($_POST['num_iade'], "int"),
GetSQLValueString($_POST['num_bloc'], "int"),
GetSQLValueString($_POST['datepicker'], "date"));

mysql_select_db($database_cnxTestDate1, $cnxTestDate1);
$Result1 = mysql_query($insertSQL, $cnxTestDate1) or die(mysql_error());
}

mysql_select_db($database_cnxTestDate1, $cnxTestDate1);
$query_rsIade = "SELECT * FROM iade";
$rsIade = mysql_query($query_rsIade, $cnxTestDate1) or die(mysql_error());
$row_rsIade = mysql_fetch_assoc($rsIade);
$totalRows_rsIade = mysql_num_rows($rsIade);

mysql_select_db($database_cnxTestDate1, $cnxTestDate1);
$query_rsbloc = "SELECT * FROM bloc";
$rsbloc = mysql_query($query_rsbloc, $cnxTestDate1) or die(mysql_error());
$row_rsbloc = mysql_fetch_assoc($rsbloc);
$totalRows_rsbloc = mysql_num_rows($rsbloc);
?>
<!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>Document sans titre</title>

<link type="text/css" href="css/style.css" rel="stylesheet" />
<link type="text/css" href="css/cupertino/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="js/ui.datepicker-fr.js"></script>

<script type="text/javascript">
$(document).ready(function() {
$("#datepicker").datepicker();
});
</script>

<style type="text/css">
#ui-datepicker-div{ font-size: 80%; }
</style>

</head>

<body>
<p>&nbsp;</p>
<form id="ajout-vacations" name="ajout-vacations" method="POST" action="<?php echo $editFormAction; ?>">
<p>
<label for="numero_vac">Numero vacation :</label>
<input type="text" name="numero_vac" id="numero_vac" accesskey="n" tabindex="1" />
</p>
<p>
<label for="libelle_vac">Nom vacation :</label>
<input type="text" name="libelle_vac" id="libelle_vac" accesskey="l" tabindex="2" />
</p>
<p>
<label for="num_iade">Numero IADE :</label>
<select name="num_iade" id="num_iade" accesskey="i" tabindex="3">
<?php
do {
?>
<option value="<?php echo $row_rsIade['num_iade']?>"><?php echo $row_rsIade['num_iade']?></option>
<?php
} while ($row_rsIade = mysql_fetch_assoc($rsIade));
$rows = mysql_num_rows($rsIade);
if($rows > 0) {
mysql_data_seek($rsIade, 0);
$row_rsIade = mysql_fetch_assoc($rsIade);
}
?>
</select>
</p>
<p>
<label for="num_bloc">Numero Bloc :</label>
<select name="num_bloc" id="num_bloc" accesskey="b" tabindex="4">
<?php
do {
?>
<option value="<?php echo $row_rsbloc['num_bloc']?>"><?php echo $row_rsbloc['num_bloc']?></option>
<?php
} while ($row_rsbloc = mysql_fetch_assoc($rsbloc));
$rows = mysql_num_rows($rsbloc);
if($rows > 0) {
mysql_data_seek($rsbloc, 0);
$row_rsbloc = mysql_fetch_assoc($rsbloc);
}
?>
</select>
</p>
<p>
<label for="dat">Date :</label>

<input type="text" id="datepicker" name="datepicker" />
</p>
<p>&nbsp;</p>
<p>
<input type="submit" name="envoi" id="envoi" value="Ajout d'une vacation" accesskey="e" tabindex="6" />
</p>
<p>&nbsp;</p>
<input type="hidden" name="MM_insert" value="ajout-vacations" />
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($rsIade);

mysql_free_result($rsbloc);
?>
SVP Merci

Raphael
Raphaelphp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 17h28   #15
Membre expérimenté
 
Avatar de buggen25
 
Inscription : août 2008
Messages : 510
Détails du profil
Informations forums :
Inscription : août 2008
Messages : 510
Points : 595
Points : 595
Bon, je Les modification sont en vert
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php require_once('Connections/cnxTestDate1.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;
 }
 }

 $editFormAction = $_SERVER['PHP_SELF'];
 if (isset($_SERVER['QUERY_STRING'])) {
 $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
 }
 $date = implode('-', array_reverse( explode('-',$_POST['datepicker']) ) ) ;
 if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "ajout-vacations")) {
 $insertSQL = sprintf("INSERT INTO vacation (num_vacation, nom_vac, num_iade, num_bloc, dat) VALUES (%s, %s, %s, %s, %s)",
 GetSQLValueString($_POST['numero_vac'], "int"),
 GetSQLValueString($_POST['libelle_vac'], "text"),
 GetSQLValueString($_POST['num_iade'], "int"),
 GetSQLValueString($_POST['num_bloc'], "int"),
 GetSQLValueString($date, "date"));

 mysql_select_db($database_cnxTestDate1, $cnxTestDate1);
 $Result1 = mysql_query($insertSQL, $cnxTestDate1) or die(mysql_error());
 }

 mysql_select_db($database_cnxTestDate1, $cnxTestDate1);
 $query_rsIade = "SELECT * FROM iade";
 $rsIade = mysql_query($query_rsIade, $cnxTestDate1) or die(mysql_error());
 $row_rsIade = mysql_fetch_assoc($rsIade);
 $totalRows_rsIade = mysql_num_rows($rsIade);

 mysql_select_db($database_cnxTestDate1, $cnxTestDate1);
 $query_rsbloc = "SELECT * FROM bloc";
 $rsbloc = mysql_query($query_rsbloc, $cnxTestDate1) or die(mysql_error());
 $row_rsbloc = mysql_fetch_assoc($rsbloc);
 $totalRows_rsbloc = mysql_num_rows($rsbloc);
 ?>
 <!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>Document sans titre</title>

 <link type="text/css" href="css/style.css" rel="stylesheet" />
 <link type="text/css" href="css/cupertino/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
 <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
 <script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
 <script type="text/javascript" src="js/ui.datepicker-fr.js"></script>

 <script type="text/javascript">
 $(document).ready(function() {
 $("#datepicker").datepicker();
 }); 
 </script> 

 <style type="text/css">
 #ui-datepicker-div{ font-size: 80%; }
 </style>

 </head>

 <body>
 <p>&nbsp;</p>
 <form id="ajout-vacations" name="ajout-vacations" method="POST" action="<?php echo $editFormAction; ?>">
 <p>
 <label for="numero_vac">Numero vacation :</label>
 <input type="text" name="numero_vac" id="numero_vac" accesskey="n" tabindex="1" />
 </p>
 <p>
 <label for="libelle_vac">Nom vacation :</label>
 <input type="text" name="libelle_vac" id="libelle_vac" accesskey="l" tabindex="2" />
 </p>
 <p>
 <label for="num_iade">Numero IADE :</label>
 <select name="num_iade" id="num_iade" accesskey="i" tabindex="3">
 <?php
 do { 
 ?>
 <option value="<?php echo $row_rsIade['num_iade']?>"><?php echo $row_rsIade['num_iade']?></option>
 <?php
 } while ($row_rsIade = mysql_fetch_assoc($rsIade));
 $rows = mysql_num_rows($rsIade);
 if($rows > 0) {
 mysql_data_seek($rsIade, 0);
 $row_rsIade = mysql_fetch_assoc($rsIade);
 }
 ?>
 </select>
 </p>
 <p>
 <label for="num_bloc">Numero Bloc :</label>
 <select name="num_bloc" id="num_bloc" accesskey="b" tabindex="4">
 <?php
 do { 
 ?>
 <option value="<?php echo $row_rsbloc['num_bloc']?>"><?php echo $row_rsbloc['num_bloc']?></option>
 <?php
 } while ($row_rsbloc = mysql_fetch_assoc($rsbloc));
 $rows = mysql_num_rows($rsbloc);
 if($rows > 0) {
 mysql_data_seek($rsbloc, 0);
 $row_rsbloc = mysql_fetch_assoc($rsbloc);
 }
 ?>
 </select>
 </p>
 <p>
 <label for="dat">Date :</label>

 <input type="text" id="datepicker" name="datepicker" />
 </p>
 <p>&nbsp;</p>
 <p>
 <input type="submit" name="envoi" id="envoi" value="Ajout d'une vacation" accesskey="e" tabindex="6" />
 </p>
 <p>&nbsp;</p>
 <input type="hidden" name="MM_insert" value="ajout-vacations" />
 </form>
 <p>&nbsp;</p>
 </body>
 </html>
 <?php
 mysql_free_result($rsIade);

 mysql_free_result($rsbloc);
 ?>
j'espère que ça va t'aider, Cordialement
__________________
If you type Google into Google, you Can break the internet" - The IT Crowd
buggen25 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 17h37   #16
Invité de passage
 
Inscription : novembre 2011
Messages : 20
Détails du profil
Informations forums :
Inscription : novembre 2011
Messages : 20
Points : 3
Points : 3
Par défaut Pb Datepicker -Fin

Salut,

cela marche tres bien

Merci de ton aide

Raphael
Raphaelphp est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2012, 17h40   #17
Membre expérimenté
 
Avatar de buggen25
 
Inscription : août 2008
Messages : 510
Détails du profil
Informations forums :
Inscription : août 2008
Messages : 510
Points : 595
Points : 595
De rien n'oublie pas de mettre résolu cordialement
__________________
If you type Google into Google, you Can break the internet" - The IT Crowd
buggen25 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 17h12.


 
 
 
 
Partenaires

Hébergement Web