Bonjour,

Je tente désespérément d'insérer des informations en base de données. En vain.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
	global $current_user; 
	$current_user = wp_get_current_user();
	if(isset($_POST['submit'])){
		/* Set Personal Information */
		$arrayPersonalInfo = setRoommatePersonalInformation('userID', $current_user);
		if(!empty($_POST['birthdate-MM']) AND
		   !empty($_POST['birthdate-DD']) AND
		   !empty($_POST['birthdate-YYYY']))	$arrayPersonalInfo = setRoommatePersonalInformation('birthdate', array(htmlspecialchars($_POST['birthdate-MM']), htmlspecialchars($_POST['birthdate-DD']), htmlspecialchars($_POST['birthdate-YYYY'])));
		if(!empty($_POST['mailingAddress']))	$arrayPersonalInfo = setRoommatePersonalInformation('mailingAddress', htmlspecialchars($_POST['mailingAddress']));
		if(!empty($_POST['city']))				$arrayPersonalInfo = setRoommatePersonalInformation('city', htmlspecialchars($_POST['city']));
		if(!empty($_POST['state']))				$arrayPersonalInfo = setRoommatePersonalInformation('state', htmlspecialchars($_POST['state']));
		if(!empty($_POST['zipCode']))			$arrayPersonalInfo = setRoommatePersonalInformation('zipCode', htmlspecialchars($_POST['zipCode']));
		if(!empty($_POST['phoneNumber']))		$arrayPersonalInfo = setRoommatePersonalInformation('phoneNumber', htmlspecialchars($_POST['phoneNumber']));
		if(!empty($_POST['emergencyName']))		$arrayPersonalInfo = setRoommatePersonalInformation('emergencyName', htmlspecialchars($_POST['emergencyName']));
		if(!empty($_POST['emergencyPhone']))	$arrayPersonalInfo = setRoommatePersonalInformation('emergencyPhone', htmlspecialchars($_POST['emergencyPhone']));
		if(!empty($_POST['school']))			$arrayPersonalInfo = setRoommatePersonalInformation('school', htmlspecialchars($_POST['school']));
 
        /* Insertion BDD */
	sqlInsertIntoRoommatePersonalInformation($arrayPersonalInfo, $current_user);
Et voici mes 2 fonctions :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?php
function setRoommatePersonalInformation($field, $value){
	try{
		if(is_array($value)) $value = $value[2].'-'.$value[0].'-'.$value[1]; /* Birth Date */
		$personalInfo[$field][] = $value;
		return $personalInfo;
	} catch (Exception $e){die('Error : ' . $e->getMessage());}
}
 
function sqlInsertIntoRoommatePersonalInformation($data, $user){
	$bdd = initDB();
	$req = $bdd->prepare('INSERT INTO sdsh_roommate_personalinfo(
							userID,
							birthdate,
							mailingAddress,
							city,
							state,
							zipCode,
							phoneNumber,
							emergencyName,
							emergencyPhone,
							school,
							passport,
							proof) VALUES(
							:userID,
							:birthdate,
							:mailingAddress,
							:city,
							:state,
							:zipCode,
							:phoneNumber,
							:emergencyName,
							:emergencyPhone,
							:school,
							:passport,
							:proof)');
	$req->execute(array(
		'userID'		 => $user->ID,
		'birthdate' 	 => $data['birthdate'],
		'mailingAddress' => $data['mailingAddress'],
		'city' 			 => $data['city'],
		'state' 		 => $data['state'],
		'zipCode' 		 => $data['zipCode'],
		'phoneNumber' 	 => $data['phoneNumber'],
		'emergencyName'  => $data['emergencyName'],
		'emergencyPhone' => $data['emergencyPhone'],
		'school' 		 => $data['school'],
		'passport' 		 => $data['passport'],
		'proof' 		 => $data['proof'],
	));
}
L'exception levée est la suivante :

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'birthdate' cannot be null' in C:\wamp\www\SDSH\wp-content\themes\sdsh\functions.php on line 296
Je dois merder avec mon array, mais où ? Merci pour votre aide.

PS: Je travaille avec le CMS WordPress, la variable $current_user contient toutes les informations du membre connecté. Simple information, juste au cas où ;-)

Bonne journée tout le monde (même si vous êtes de Toulouse..)