slt,
actuellement je m'exerce a comprendre le fonctionnement de la connexion a une base mysql apartir s'un script php dont voici le code:
page "search.html":
page "result.php";
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 <html> <head> <title>Book-O-Rama Catalog Search</title> </head> <body> <h1>Book-O-Rama Catalog Search</h1> <form action="results.php" method="post"> Choose Search Type:<br /> <select name="searchtype"> <option value="author">Author</option> <option value="title">Title</option> <option value="isbn">ISBN</option> </select> <br /> Enter Search Term:<br /> <input name="searchterm" type="text"> <br /> <input type="submit" value="Search"> </form> </body> </html>
ma base s'appelle books et j'ai créé un utilisateur avec le login et le mot de passe cité ci dessus, mais voila lors de la recherche j'ai seulement le titre qui s'affiche, je n'obtiens pas le resultat attendu a savoir le nom de l'ecrivain, le nom du livre, etc...
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 <html> <head> <title>Book-O-Rama Search Results</title> </head> <body> <h1>Book-O-Rama Search Results</h1> <?php // create short variable names $searchtype=$_POST['searchtype']; $searchterm=$_POST['searchterm']; $searchterm= trim($searchterm); if (!$searchtype || !$searchterm) { echo 'You have not entered search details. Please go back and try again.'; exit; } if (!get_magic_quotes_gpc()) { $searchtype = addslashes($searchtype); $searchterm = addslashes($searchterm); } @ $db = new mysqli('localhost', 'bookorama', 'bookorama123', 'books'); if (mysqli_connect_errno()) { echo 'Error: Could not connect to database. Please try again later.'; exit; } $query = "select * from books where ".$searchtype." like '%".$searchterm."%'"; $result = $db->query($query); $num_results = $result->num_rows; echo '<p>Number of books found: '.$num_results.'</p>'; for ($i=0; $i <$num_results; $i++) { $row = $result->fetch_assoc(); echo '<p><strong>'.($i+1).'. Title: '; echo htmlspecialchars(stripslashes($row['title'])); echo '</strong><br />Author: '; echo stripslashes($row['author']); echo '<br />ISBN: '; echo stripslashes($row['isbn']); echo '<br />Price: '; echo stripslashes($row['price']); echo '</p>'; } $result->free(); $db->close(); ?> </body> </html>
qu'ai je oublié?
merci
Partager