Checking if record already exists in MySQL?

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
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

Checking if record already exists in MySQL?

Post by dominod »

Hi

I want to check if a record already exist in MySQL database. If it does it shuld echo "It does exist" and if it dont it shuld do nothing..

Now I figured out the following code but it will not work or give me a error message :

Code: Select all

if(mysql_num_rows(mysql_query("SELECT * FROM engines WHERE keyword = '$GKeyword'"))){
echo "Its there";
}
Can anyone help me? :?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Checking if record already exists in MySQL?

Post by requinix »

Code: Select all

mysql_query("SELECT * FROM engines WHERE keyword = '$GKeyword'") or die(mysql_error());
What happens if you do that?
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

Re: Checking if record already exists in MySQL?

Post by dominod »

Thanks tasairis but I got the answer from DigitalPoint :)

Have a nice day
Post Reply