Bonjour,
J'ai un script qui est fourni sans l'écriture de la base de données, alors j'ai créé la base de données grosso-modo en fonction du script, mais j'ai des erreurs dans mysql durant l'exécution du script. Je débute en php et je ne trouve pas cette erreur.
Voici le script :
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 <!-- Listing 17-5: editing data from database (comment_edit.php) --> <?php // Open connection to the database mysql_connect("**", "***", "***") or die("Failure to communicate with database"); mysql_select_db("eonintermail"); if ($_POST['submit'] == 'Submit') { // Format the data $comment_id = $_POST['comment_id']; $comment_header = $_POST['comment_header']; $as_comment_header = addslashes($comment_header); $comment = $_POST['comment']; $as_comment = addslashes($_POST['comment']); // Update values $query = "UPDATE comments SET comment_header = 'uy', comment = 'uy' WHERE ID = 0"; $result = mysql_query($query); if (mysql_affected_rows() == 1) { $success_msg = '<P>Your comment has been updated.</P>'; } else { error_log(mysql_error()); $success_msg = '<P>Something went wrong.</P>'; echo mysql_error(); } } else { // Get the comment header and comment $comment_id = $_GET['comment_id']; $query = "SELECT comment_header, comment FROM comments WHERE ID = $comment_id"; $result = mysql_query($query); $comment_arr = mysql_fetch_array($result); $comment_header = stripslashes($comment_arr[0]); $comment = stripslashes($comment_arr[1]); echo mysql_error(); } $thispage = $_SERVER['PHP_SELF']; //Have to do this for heredoc $form_page = <<< EOFORMPAGE <STYLE TYPE="text/css"> <!-- BODY, P {color: black; font-family: verdana; font-size: 10 pt} H1 {color: black; font-family: arial; font-size: 12 pt} --> </STYLE> </HEAD> <BODY> <TABLE BORDER=0 CELLPADDING=10 WIDTH=100%> <TR> <TD BGCOLOR="#F0F8FF" ALIGN=CENTER VALIGN=TOP WIDTH=17%> </TD> <TD BGCOLOR="#FFFFFF" ALIGN=LEFT VALIGN=TOP WIDTH=83%> <H1>Comment edit</H1> $success_msg <FORM METHOD="post" ACTION="$thispage"> <INPUT TYPE="text" SIZE="40" NAME="comment_header" VALUE="$comment_header"><BR><BR> <TEXTAREA NAME="comment" ROWS=10 COLS=50>$comment</TEXTAREA><BR><BR> <INPUT TYPE="hidden" NAME="comment_id" VALUE="$comment_id"> <INPUT TYPE="submit" NAME="submit" VALUE="Submit"> </FORM> </TD></TR></TABLE> </BODY> </HTML> EOFORMPAGE; echo $form_page; ?>
Et voici un export de la base de données :
Code SQL : 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 `comments` -- CREATE TABLE IF NOT EXISTS `comments` ( `ID` varchar(50) NOT NULL default '', `comment_header` varchar(200) NOT NULL default '', `comment` varchar(200) NOT NULL default '' ) TYPE=MyISAM; -- -- Contenu de la table `comments` -- INSERT INTO `comments` (`ID`, `comment_header`, `comment`) VALUES ('0', 'iddii', 'iii');
Pouvez-vous m'aider à comprendre d'où vient le problème ?
J'ai mis des echo mysql_error(); mais je ne comprends pas plus.
Partager