Sending Friendship [closed]

0

Hello! I am creating a social network type system. But I caught on to sending a friend request. I created the user and friendship tables, but I am not able to insert. It keeps saying that it gave error in the line of the query. It looks like the error is time to insert into the table.

HTML:

<formmethod="POST">
  <h2><?php echo $saber["nome"]; ?></h2><br/>
  <?php
    $amigos = mysqli_query($con,"SELECT * FROM amizades WHERE de='$login_cookie' AND para='$email' OR para='$login_cookie' AND de='$email'");
    $amigoss = mysqli_fetch_assoc($amigos);
    if (mysqli_num_rows($amigos)>=1 AND $amigoss["aceite"]=="sim") {
      echo '<input type="submit" value="Remover amigo" name="remover"><input type="submit" name="denunciar" value="Denunciar">';
    }elseif (mysqli_num_rows($amigos)>=1 AND $amigoss["aceite"]=="nao" AND $amigoss["de"]==$login_cookie){
      echo '<input type="submit" value="Cancelar pedido" name="cancelar"><input type="submit" name="denunciar" value="Denunciar">';
    }else{
      echo '<input type="submit" value="Adicionar amigo" name="add"><input type="submit" name="denunciar" value="Denunciar">';
    }
  ?>
  </form>

PHP

if (isset($_POST['add'])) {
  add();
}

function add(){
  $login_cookie = $_COOKIE['login'];
  if (!isset($login_cookie)) {
    header("Location: login.php");
  }
  $con = mysqli_connect("localhost","root","","rede");
  $id = $_GET['id'];
  $saberr = mysqli_query($con, "SELECT * FROM usuario WHERE id='$id'");
  $saber = mysqli_fetch_assoc($saberr);
  $email = $saber['email'];
  $data = date("Y/m/d");

  $ins = "INSERT INTO amizades (de, para, data) VALUES ('".$login_cookie."','".$email."','".$data."')";
    $conf = mysqli_query($con, $ins) or die(mysqli_error());

  if($conf) {
    header("Location: profile.php?id=".$id);
  }else{
    echo "<h3>Erro ao enviar pedido...</h3>";
  }
}
    
asked by anonymous 01.09.2017 / 21:02

1 answer

2

You need to pass the connection link with the database to the mysql error function

$conf = mysqli_query($con, $ins) or die(mysqli_error($con));
    
01.09.2017 / 21:52