The following is passed to the browser: http://localhost/like.php?f=1
where f=1 is the article ID which I would like to like. There is a user system and I would only like them to be able to like the article once (for obvious reasons). My code, pulls the information from the database about the article, then pulls through the user information (to get there ID from the current session) then checks to see if the user already liked this, and if not insert into the like database, or return back to the article page. Here is the code I have so far..
As you can see in the code, I’ve been trying to debug, but it’s not going well…
<?php
include "connect.php";
session_start();
$feed = $_GET['f'];
$feeddb = "SELECT * from feeddb where ID=$feed";
$feeddb2 = mysql_query($feeddb) or die("Whuuut?");
$feeddb3 = mysql_fetch_array($feeddb2);
if (isset($_SESSION['usrname']))
{
$player=$_SESSION['usrname'];
$userstats="SELECT * from feedus where tit='$player'";
$userstats2=mysql_query($userstats) or die("Could not get user stats");
$userstats3=mysql_fetch_array($userstats2);
$feedli = "SELECT * from feedli where PID=$feed";
$feedli2 = mysql_query($feedli) or die("Could not get likes");
while($feedli3=mysql_fetch_array($feedli2))
{
if($userstats3['ID'] == $feedli3['UID'])
{
echo $userstats3[ID];
echo $feedli3[UID];
} else {
$updatelike =
"INSERT into feedli (PID, UID) values('$feed','$userstats3[ID]')";
$updatelike2 = mysql_query($updatelike);
echo $userstats3[ID];
echo $feedli3[UID];
}
}
}
else
{
}
?>
Any help would be appreciated!
Edit: For Clarity – I would like the code to insert the PID (article ID which is in $feed) and UID (which is the users ID in $userstats3[ID]) into the table FEEDLI if they haven’t liked this article before, if they have, skip the code and go back to the previous article.
i think you are not using $feeddb3 in the code.. this might be usefull. also try to avoid sql injections.