Bonjour,
Je voudrais metre à jour un champ email, mais cela ne marche pas.
J'ai essayer avec les lignes de débuguage mais je ne trouve pas plus. L'une d'elle réécrit la requete masql qui est générée. Si je la teste dans phpmyadmin, cela ne donne pas d'erreur, mais mon champ mail n'est pas plus mis à jour.
Voici l'export de ma base :
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 -- Structure de la table `checkbox` -- CREATE TABLE IF NOT EXISTS `checkbox` ( `BoxValue` tinyint(1) default NULL, `BoxName` varchar(100) NOT NULL default '', `email` varchar(100) NOT NULL default '' ) TYPE=MyISAM; -- -- Contenu de la table `checkbox` -- INSERT INTO `checkbox` (`BoxValue`, `BoxName`, `email`) VALUES (1, 'OptOut', 'eert@toto.fr');
Et voici le script
Au premier chargement de la page il n'y a pas d'erreur, mais après la tentative de mise à jour, voici le texte généré dans la page :
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
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 <!-- Listing 17-6: checkbox displaying boolean data from database (optout.php) --> <?php // Open connection to the database mysql_connect("***", "***", "***") or die("Failure to communicate with database"); mysql_select_db("***"); // If the form has been submitted, record the preference and redisplay if ($_POST['submit'] == 'Submit') { $email = $_POST['email']; $as_email = addslashes($_POST['email']); if (isSet($_POST['OptOut']) && ($_POST['OptOut'] == 1)) { $optout = 1; } else { $optout = 0; } // Update value $query = "UPDATE checkbox SET BoxValue = $optout WHERE BoxName = 'OptOut' AND email = '$as_email'"; /* Affichage de débuggage */ echo("<pre>\n"); var_dump($query); echo("</pre>\n"); /* Fin affichage débuggage */ $result = mysql_query($query or die("ERR : " . mysql_error() . "<br />SQL : " . $query)); if (mysql_error() == "") { $success_msg = '<P>Your preference has been updated.</P>'; } else { error_log(mysql_error()); echo mysql_error(); $success_msg = '<P>Something went wrong.</P>'; } // Get the value $query = "SELECT BoxValue FROM checkbox WHERE BoxName = 'OptOut' AND email = '$as_email'"; /* Affichage de débuggage */ echo("<pre>\n"); var_dump($query); echo("</pre>\n"); /* Fin affichage débuggage */ $result = mysql_query($query or die("ERR : " . mysql_error() . "<br />SQL : " . $query)); $optout = mysql_result($result, 0, 0); if ($optout == 0) { $checked = ""; } elseif ($optout == 1) { $checked = 'CHECKED'; } } // Now display the page $thispage = $_SERVER['PHP_SELF']; //Have to do this for heredoc $form_page = <<< EOFORMPAGE <HTML> <HEAD> <TITLE>Semi-sleazy opt-in form</TITLE> </HEAD> <BODY> $success_msg <FORM METHOD=POST ACTION="$thispage"> Email address: <INPUT TYPE="text" NAME="email" SIZE=25 VALUE="$email"><BR><BR> <FONT SIZE=+4>Please send me lots of e-mail bulletins!</FONT><BR> <FONT SIZE=-2>opt out by clicking this tiny checkbox</FONT> <INPUT TYPE="checkbox" NAME="OptOut" VALUE=1 $checked><BR><BR> <INPUT TYPE="submit" NAME="submit" VALUE="Submit"> </FORM> </BODY> </HTML> EOFORMPAGE; echo $form_page; ?>
Quelqu'un peut-il me dire ce qui se passe ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 string(116) "UPDATE checkbox SET BoxValue = 1 WHERE BoxName = 'OptOut' AND email = 're@fg.fr'" You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 string(77) "SELECT BoxValue FROM checkbox WHERE BoxName = 'OptOut' AND email = 're@fg.fr'" Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /homez.63/eoninter/www/php/optout.php on line 45 Something went wrong.
Partager