-
Notifications
You must be signed in to change notification settings - Fork 0
/
savfav.php
71 lines (58 loc) · 1.96 KB
/
savfav.php
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
<!DOCTYPE html>
<html>
<head>
<title>Poodle</title>
<table align="right"><br>
<tr><td align="right"><form action="search.php" method="get" >
<input type="text" size="40" name="keyword" ><input type="submit" name="sub" value="Explore" />
</form>
</td></tr></table>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php include "master.php"; ?>
</head>
<body>
<?php
session_start();
$doc_id = $_REQUEST["id1"];
$item = $_REQUEST["id2"];
$_SESSION["var"] = $doc_id ;
#echo $_SESSION["var"];
$servername="localhost";
$username="admin";
$pass="monarchs";
$db="userlog";
$conn=mysqli_connect($servername,$username,$pass,$db);
if($conn->connect_error){
die("Connection failed:".$conn->connect_error);
}
#else echo"Successfully connected to the database!<br>";
if(empty($doc_id))
echo "Failure to fetch doc id!<br>";
else
{
$uId = $_SESSION['uId'];
$sql="SELECT * FROM favourites WHERE uname = '{$uId}' AND doc_id = '{$doc_id}' ";
$result = $conn->query($sql);
$rows = @ mysqli_num_rows($result);
if ($rows>0)
{
$row = mysqli_fetch_array($result);
$row_id = $row["id"];
#$update= "UPDATE favourites SET savetime = now(), doc_id = '{$doc_id}' WHERE id={$row_id}";
$update= "UPDATE favourites SET savetime = now(), doc_id = '{$doc_id}' , item = '{$item}' WHERE id={$row_id}";
$result = $conn-> query($update);
echo "Updated";
echo "<a href='http://localhost/Poodle.com/collections.php'><br>Go to Collections <a/>";
}
else
{
#$add = "INSERT INTO favourites (uname, doc_id, item, savetime) VALUES ( '{$uId}' , '{$doc_id}' , 'null' , now() )";
$add = "INSERT INTO favourites (uname, doc_id,item, savetime) VALUES ( '{$uId}' , '{$doc_id}' ,' {$item}' , now() )";
$result = $conn-> query($add);
echo "Saved";
echo "<a href='http://localhost/Poodle.com/collections.php'><br>Go to Collections <a/>";
}
}
?>
</body>
</html>