PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
What this code is supposed to do, is search a database entry called userviews from the row specified in $_GET[id], that's formatted like this: "Username Username2 Username3 Username4" for the current session username, and if it's not in that entry, add it to the end, proceeded by a single space.
//record that the user has read the post
$check = mysql_query("SELECT COUNT '$_SESSION[username]' FROM replies WHERE userviews = '$_GET[id]'");
$uV = mysql_fetch_array($check);
if($uV["COUNT(*)"] == 1){
NULL;
} else {
$previousUV = mysql_query("SELECT * FROM replies WHERE userviews = '$_GET[id]'");
$userv = $previousUV . " " . $_SESSION[username];
mysql_query("UPDATE replies SET uservies = '$userv' WHERE id='$id'");
}
I cannot understand that are you doing? But in any event if you are using mysql_query() you should use mysql_error in pair. It help you to understand where you do a syntactic error.
<?
//...
//record that the user has read the post
$check = mysql_query("SELECT COUNT '$_SESSION[username]' FROM replies WHERE userviews = '$_GET[id]'") or die(mysql_error());
$uV = mysql_fetch_array($check);
if($uV["COUNT(*)"] == 1){
NULL;
} else {
$previousUV = mysql_query("SELECT * FROM replies WHERE userviews = '$_GET[id]'") or die(mysql_error());
$userv = $previousUV . " " . $_SESSION[username];
mysql_query("UPDATE replies SET uservies = '$userv' WHERE id='$id'") or die(mysql_error());
}
//...
?>