Page 1 of 1

Need some help with my MySQL syntax.

Posted: Fri Oct 31, 2008 5:56 pm
by Moargazm
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.

I'm SURE I screwed up the syntax somewhere.

Code: Select all

//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'");
}

Re: Need some help with my MySQL syntax.

Posted: Sat Nov 01, 2008 9:54 am
by zephyr750
It may be a case of stating the obvious......

Isn't your problem on line 9? (***uservies***)

mysql_query("UPDATE replies SET ***uservies*** = '$userv' WHERE id='$id'");

Re: Need some help with my MySQL syntax.

Posted: Sat Nov 01, 2008 4:49 pm
by Ziq
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.

Code: Select all

 
<?
//...
//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());
}
//...
?>