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.
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.
– teliz
Put the bug, it’s hard without
– Rafael Augusto
http://prntscr.com/gfy0bi
– OliverDamon
Exchange the photo for text.
– Guilherme Nascimento
Field 'id' doesn’t have a default value
– OliverDamon
Got n created id int Primary key auto_increment.
– OliverDamon