-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.php
38 lines (38 loc) · 1.27 KB
/
post.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
<?php
$sql = "SELECT portfolio FROM stocks WHERE stock =? AND username =?";
require "./include/connhandler.php";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ss", $stockid, $username);
$stockid = $_GET["stock"];
$username = $_GET["username"];
$change = $_GET["change"];
$date = new DateTime();
$timestamp = $date->getTimestamp();
$stmt->execute();
$result = $stmt->get_result();
$stmt->close();
$conn->close();
if ($row = $result->fetch_assoc()){
foreach ($row as $r){
$change = $r + $change;
$sql = "UPDATE stocks SET portfolio =?, timestamp =? WHERE username =? AND stock =?";
require "./include/connhandler.php";
if($stmt = $conn->prepare($sql)){
$stmt->bind_param("iiss", $change, $timestamp, $username, $stockid);
$stmt->execute();
$stmt->close();
$conn->close();
print "had $r now has $change";
}else{exit();}
}
}else {
$sql = "INSERT INTO stocks (stock, username, portfolio, timestamp) VALUES (?, ?, ?, ?)";
require "./include/connhandler.php";
if($stmt = $conn->prepare($sql)){
$stmt->bind_param("ssii", $stockid, $username, $change, $timestamp);
$stmt->execute();
$stmt->close();
$conn->close();
}else{exit();}
}
?>