Jump to content

[SOLVED] New to PHP....help with query please!


Recommended Posts

I am trying to get records from the database where the username= $username and the comment does not equal $comment. Ive heard != means not equal so this is what i have so far:

 

 $sql="select * from comments where (tousername= '$username') AND (commment != $comment) ORDER by date";

 

im not sure if its meant to be in brackets??? I basically dont have a clue what im doing..

Link to comment
https://forums.phpfreaks.com/topic/64846-solved-new-to-phphelp-with-query-please/
Share on other sites

unless $comment is a number, you need single quotes around it

 

comment != '$comment'

 

also, sometimes it works better to use NOT LIKE instead.

 

comment NOT LIKE '$comment'

 

this also lets you throw in some wildcard, like:

 

comment NOT LIKE '%$comment$'

check your comment comparison... isn't it supposed to be string?

 

instead of:

$sql="select * from comments where (tousername= '$username') AND (commment != $comment) ORDER by date";

try

$sql="select * from comments where (tousername= '$username') AND (commment != '$comment') ORDER by date";

 

also, don't forget to check for other syntax, such as spelling. commment?

 

regards.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.