MYSQL insert if else update issue

Hi,

its been asked before but i can’t seem to solve this issue.
trying to create my own page view script and having said that I’m trying to update a table based on IP address in the database or not. tried different iteration with no success and could use some help solving this problem.

  • the IP address field is setup as a unique field: test_visitedIP

so if test_visitedIP NOT in the table append the the IP address and add one to the test_count else
increment countIP plus one

     $userIP =  '192.168.0.17';     
    try{
      $SMT1=$dbcon->prepare("INSERT INTO tbl_testTB (test_visitedIP,  test_count)
                            VALUES(:userIP, :countIP)
                            ON DUPLICATE KEY UPDATE
                            test_count = test_count + 1");
     $SMT1->bindParam(':userIP',  $userIP);    
     $SMT1->bindParam(':countIP',  1);
      $SMT1->execute();   
    } catch(PDOException $e) { echo 'Unable to update DB : ' . $e->getMessage();   }

Thanks

just to confirm, could you please do a SHOW CREATE TABLE

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.