My code is the one here
<?php
include("header.php");
$id = $_GET["id"];
$saberr = mysqli_query($conecta, "SELECT * FROM users WHERE id='$id'");
$saber = mysqli_fetch_assoc($saberr);
$email = $saber["email"];
if ($email==$login_cookie) {
header("Location: myprofile.php");
}
$pubs = mysqli_query($conecta, "SELECT * FROM pubs WHERE user='$email' ORDER BY id desc");
if (isset($_POST['add'])) {
add();
}
function add(){
$login_cookie = $_COOKIE['login'];
if (!isset($login_cookie)) {
header("Location: login.php");
}
$id = $_GET['id'];
$saberr = mysqli_query($conecta, "SELECT * FROM users WHERE id='$id'");
$saber = mysqli_fetch_assoc($saberr);
$email = $saber['email'];
$data = date("Y/m/d");
$conf = mysqli_query($conecta, "INSERT INTO amizades ('de', 'para', 'data') VALUES ('$login_cookie','$email','data')") or die(mysqli_error($conecta));
if ($conf) {
header("Location: profile.php?id=".$id);
}else{
echo "<h3>Erro ao enviar pedido...</h3>";
}
}
if (isset($_POST['cancelar'])) {
cancel();
}
function cancel(){
$login_cookie = $_COOKIE['login'];
if (!isset($login_cookie)) {
header("Location: login.php");
}
$id = $_GET['id'];
$saberr = mysqli_query($conecta, "SELECT * FROM users WHERE id='$id'");
$saber = mysqli_fetch_assoc($saberr);
$email = $saber['email'];
$ins = "DELETE FROM amizades WHERE 'de'='$login_cookie' AND para='$email'";
$conf = mysqli_query($conecta, $ins) or die(mysql_error());
if ($conf) {
header("Location: profile.php?id=".$id);
}else{
echo "<h3>Erro ao cancelar pedido...</h3>";
}
}
if (isset($_POST['remover'])) {
remove();
}
if (isset($_POST['chat'])) {
header("Location: chat.php?from=".$id);
}
function remove(){
$login_cookie = $_COOKIE['login'];
if (!isset($login_cookie)) {
header("Location: login.php");
}
$id = $_GET['id'];
$saberr = mysqli_query($conecta, "SELECT * FROM users WHERE id='$id'");
$saber = mysqli_fetch_assoc($saberr);
$email = $saber['email'];
$ins = "DELETE FROM amizades WHERE 'de'='$login_cookie' AND para='$email' OR 'para'='$login_cookie' AND de='$email'";
$conf = mysqli_query($conecta, $ins) or die(mysqli_error());
if ($conf) {
header("Location: profile.php?id=".$id);
}else{
echo "<h3>Erro ao eliminar amizade...</h3>";
}
}
if (isset($_POST['aceitar'])) {
aceitar();
}
function aceitar(){
$login_cookie = $_COOKIE['login'];
if (!isset($login_cookie)) {
header("Location: login.php");
}
$id = $_GET['id'];
$saberr = mysqli_query($conecta, "SELECT * FROM users WHERE id='$id'");
$saber = mysqli_fetch_assoc($saberr);
$email = $saber['email'];
$ins = "UPDATE amizades SET 'aceite'='sim' WHERE 'de'='$email' AND para='$login_cookie'";
$conf = mysqli_query($ins) or die(mysqli_error());
if ($conf) {
header("Location: profile.php?id=".$id);
}else{
echo "<h3>Erro ao eliminar amizade...</h3>";
}
}
?>