Sending of Friendship

Asked

Viewed 152 times

0

Hello! I’m creating a social networking system. But I stopped by sending friend request. I created the user and friendship tables, but I’m not able to insert it. It keeps saying that there was error in the query line. It seems that the error is at the time of inserting in the table.

inserir a descrição da imagem aqui

HTML:

<form method="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>";
  }
}
  • Post your error message.

  • Put the bug, it’s hard without

  • http://prntscr.com/gfy0bi

  • Exchange the photo for text.

  • Field 'id' doesn’t have a default value

  • Got n created id int Primary key auto_increment.

Show 1 more comment

1 answer

2


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

$conf = mysqli_query($con, $ins) or die(mysqli_error($con));
  • It appeared here: Field 'id' doesn’t have a default value

  • Got n created id int Primary key auto_increment.

  • I’m glad it worked out.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.