-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiheartquotes_search.php
More file actions
48 lines (43 loc) · 1.07 KB
/
iheartquotes_search.php
File metadata and controls
48 lines (43 loc) · 1.07 KB
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
<?php
include("includes/funzioni.php");
if (isset($_GET['num'])) {
?>
<!DOCTYPE html>
<html>
<head>
<title>Iheartquotes random quotes search</title>
</head>
<body>
<div>
<?php
for($i=0; $i<$_GET['num']; $i++) {
$page_content = file_get_contents('http://iheartquotes.com/api/v1/random?format=json');
$json = json_decode($page_content);
$quotes[$i]['quote'] = $json->quote;
}
echo $_GET['num']." citazioni raccolte correttamente dal web.<br />";
$db = apri_connessione();
$count = 0;
for($i=0; $i<$_GET['num']; $i++) {
$query = "INSERT INTO `av_quotes` (
`quote`
)
VALUES (
'".mysql_real_escape_string($quotes[$i]['quote'])."'
);
";
if (!$result = mysql_query($query, $db)) {
echo mysql_error()."<br />";
echo $query."<br />";
mysql_close($db);
die("Problemi l'esecuzione della query.");
}
$count++;
}
echo $count." citazioni inserite correttamente nel DB.";
mysql_close();
} else echo "Hai provato ad usare il paramentro 'num' nella query?";
?>
</div>
</body>
</html>