It's possible to make the code more compact, but at the expense of readability, and it would be the same algorithm anyway. However, you can push the decision to insert or update down to the SQL query itself. MySQL and similar have IF statements as well as WHERE NOT EXISTS. You generally get higher performance the more you shift data manipulation to the database engine, but the benefit is not obvious in most applications, so what you have should be good.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!