Home > Backend Development > PHP Tutorial > php-在微信mysql中想实现:当记录不存在时insert,当记录存在时update 出了点问题》》

php-在微信mysql中想实现:当记录不存在时insert,当记录存在时update 出了点问题》》

WBOY
Release: 2016-06-02 11:34:17
Original
975 people have browsed it

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template