Heim > Artikel > Backend-Entwicklung > php-在微信mysql中想实现:当记录不存在时insert,当记录存在时update 出了点问题》》
php微信开发
<code>if($keyword==1||$keyword==2){ $sql_insert="INSERT INTO `760827`.`session` (`id`,`openid`,`status`) VALUES ('','$fromUsername','$keyword');"; $sql_update="UPDATE `760827`.`session` SET `status` = '$keyword' WHERE `session`.`openid` =$fromUsername;"; $sql_yanzheng="SELECT * FROM `760827`.`session` WHERE 'openid'=$fromUsername;"; $result_yanzheng=mysql_query($sql_yanzheng,$conn); if($keyword==1){ if(mysql_num_rows($result_yanzheng) > 0){ $reply="update"; echo _response_text($reply); //mysql_query($sql_update,$conn); } elseif(mysql_num_rows($result_yanzheng) == 0){ $reply="insert"; //和下面的echo构成微信输出函数 echo _response_text($reply); //mysql_query($sql_insert,$conn); } } elseif($keyword==2){ if(mysql_num_rows($result_yanzheng) > 0){ mysql_query($sql_update,$conn); } else{ mysql_query($sql_insert,$conn); } $reply="请输入您的留言:"; echo _response_text($reply); } }</code>