我目前遇到以下问题的问题:
INSERT INTO likes (idUsuario, idTweet)
SELECT {$_SESSION['idUsuario']}, {$id} FROM tweet
WHERE EXISTS (SELECT idTweet FROM tweet WHERE idTweet={$id})
AND NOT EXISTS(
SELECT idTweet FROM likes
WHERE idUsuario ={$_SESSION['idUsuario']} AND idTweet = {$id})
LIMIT 1
在myphpadmin的SQL选项卡中检查时,我不断收到指向“$,[”
等字符的错误在botton上它说我在
附近有语法错误'['idUsuario']}, {$id} FROM tweet
WHERE EXISTS (SELECT idTweet FROM tw'
我不确定这里的错误是什么。任何帮助都会很好!
编辑:我道歉,这是完整的代码。基本上,我正在制作像页面一样的高音扬声器。在这里,我显示我跟随的人的推文,我有一个像按钮(这是我遇到查询的问题,因为它没有在我的数据库中插入任何东西):
<?php
session_start();
include('db.php');
$idUser = $_SESSION['idUsuario'];
$mensaje = "";
if(isset($_POST['enviar'])){
$tweet = $_POST['tweet'];
if($_POST['tweet'] != ""){
$query = "INSERT INTO `tweet`(`idUsuario`, `tweet`) VALUES (".$idUser.",'".$tweet."')";
consulta($query);
}
}
error_reporting(0);
$usuariolog = $_GET['idUsuario'];
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/inicio.css">
<title>Inicio</title>
</head>
<body>
<form action="perfilUsuario.php" method="GET">
<input type="submit" placeholder="Perfil">
<?php
$usuariolog = $idUser;
?>
<input type="text" name="idUsuario" value=<?php echo "$idUser" ?>>
</form>
<form method="POST" action="#" enctype="multipart/form-data">
<textarea style="resize:none" id="caja" name="tweet" placeholder="Twittea!"></textarea>
<div>
<input id="boton" type="submit" name="enviar" value="tuit">
</div>
</form>
<?php
$usuarioSeguido = 'select z.idUsuarioSeguido from follow z where z.idUsuarioSigue = '.$_SESSION['idUsuario'];
$resUsuario = consulta($usuarioSeguido);
$sUser = '';
while($resQ = mysqli_fetch_array($resUsuario)){
$sUser .= $resQ['idUsuarioSeguido'].',';
}
$sUser = substr($sUser, 0, strlen($sUser) -1);
//$sUser .= $_SESSION['idUsuario'];
$tweets = 'select * from usuario a, tweet b
where a.idUsuario = b.idUsuario
AND b.idUsuario in ('.$sUser.') and a.estatus = 1 and b.estatus = 1
order by b.fecha desc, b.idTweet desc; ';
$resTweet = consulta($tweets);
?>
<form action="carga_imagen.php" method="post" enctype="multipart/form-data">
</form>
<div id="bodyApp">
<table style="width: 50%; ">
<?php
while($tweet = mysqli_fetch_array($resTweet)){
?>
<tr style="border:#DEEDED solid 1px; ">
<td style="width:10%">
<img src="img/user.jpg" alt="" style="width:20px;">
</td>
<td style="width:89%; ">
<p>
<?php echo $tweet['tweet']?>
</p>
<small>
<?php echo $tweet['userName']?>
</small>
<small>
<?php echo $tweet['fecha']?><br><br>
<a href="inicio.php?type=tweet%id=<?php echo $tweet['idTweet'];?>">Like! </a><br>
</small>
</td>
</tr>
<?php
}
$query = "
SELECT tweet.idTweet, tweet.tweet
FROM
tweet
";
$rQ = consulta($query);
if(isset($_GET['type'], $_GET['id']))
{
$type = $_GET['type'];
$id = $_GET['id'];
}
if($type == "tweet"){
$QU = "
INSERT INTO likes (idUsuario, idTweet)
SELECT {$_SESSION['idUsuario']}, {$id} FROM tweet
WHERE EXISTS (SELECT idTweet FROM tweet WHERE idTweet={$id})
AND NOT EXISTS(
SELECT idTweet FROM likes
WHERE idUsuario ={$_SESSION['idUsuario']} AND idTweet = {$id})
LIMIT 1
";
consulta($QU);
print_r($);
header("location:inicio.php");
}
?>
</table>
</div>
</div>
</body>
</html>