-
Notifications
You must be signed in to change notification settings - Fork 0
/
posts.php
executable file
·65 lines (42 loc) · 1.22 KB
/
posts.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
<?php
session_start();
//include('database.php');
function sanitizeString($var)
{
$var = strip_tags($var);
$var = htmlentities($var);
$var = stripslashes($var);
return ($var);
}
//Get data from the form
$content = sanitizeString($_POST['content']);
$UID = sanitizeString($_POST['UID']);
//New Codes
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "root";
$dbname = "myDB";
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
if( mysqli_connect_errno($conn)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//End
//connect to DB
//$conn = connect_db();
$result = mysqli_query($conn, "SELECT * FROM users WHERE id = '$UID'");
$row = mysqli_fetch_assoc($result);
//Fetch User information
// ----
$name = sanitizeString($row["first_name"]);
$profile_pic = $row["profile_pic"];
echo "$name";
$result_insert = mysqli_query($conn, "INSERT INTO posts (content, UID, name, profile_pic, likes) VALUES ('$content', $UID, '$name', '$profile_pic', 0)");
//check if insert was okay
if($result_insert){
//redirect to feed page
header("Location: feed.php");
}else{
//throw an error
echo "Oops! Something went wrong! Please try again!";
}
?>