-2
My code and this one
<?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>";
}
}
?>
$connects is included in header.php? If so, make sure it’s global. If not, try declaring $connects within your scope of that page and see if the error persists, please. From what I saw, $connects is not stated in this scope.
– NDelavi
Was it just that mistake? If
$conecta
nothing in the code will work because it is simply the connection variable to the database.– user60252
I took out the $connects but it appears these errors Warning: mysqli_query() expects at least 2 Parameters, 1 Given in C: xampp htdocs rede profile.php on line 25 Warning: mysqli_fetch_assoc() expects Parameter 1 to be mysqli_result, null Given in C: xampp htdocs rede profile.php on line 26 Warning: mysqli_query() expects at least 2 Parameters, 1 Given in C: xampp htdocs rede profile.php on line 31 Notice: Undefined variable: connect in C: xampp htdocs rede profile.php on line 31 Warning: mysqli_error() expects Parameter 1 to be mysqli, null Given in C: xampp htdocs rede profile.php on line 31
– Fabio Venceslau de Souza