Need some help with my MySQL syntax.

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!

Moderator: General Moderators

Post Reply
Moargazm
Forum Newbie
Posts: 6
Joined: Fri Oct 31, 2008 2:08 pm

Need some help with my MySQL syntax.

Post 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'");
}
zephyr750
Forum Newbie
Posts: 6
Joined: Sat Nov 01, 2008 8:05 am

Re: Need some help with my MySQL syntax.

Post 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'");
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: Need some help with my MySQL syntax.

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