Jump to content

Checking if record already exists in MySQL?


dominod

Recommended Posts

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 :

if(mysql_num_rows(mysql_query("SELECT * FROM engines WHERE keyword = '$GKeyword'"))){
echo "Its there";
}

 

Can anyone help me?

formally speaking, your code seems to be good.

 

[...]

$my_res = mysql_query("SELECT * FROM engines WHERE keyword = '$GKeyword'");

if ( is_resource($my_res) {

    $founded = mysql_num_rows($my_res);

    if( $founded == 1){
    
        echo "founded one result, as expecteed" . "<br />";

    } else {

   die("there is a problem: founded $founded entries");

   }

} else {

    die("no resource created");    

}

[...]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.