Home  >  Article  >  Backend Development  >  How to add data to database in php

How to add data to database in php

藏色散人
藏色散人Original
2021-12-31 09:27:517000browse

php method to add data to the database: 1. Declare character encoding; 2. Connect to the database; 3. Get data; 4. Through "insert into user_info (userId, userName, phoneNumber, userScore)..." Just insert data.

How to add data to database in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How does php add data to the database?

php adds data to the database

Front-end code:

function submit_result() {             
                $.post(
                    "Controllers/ajaxController.php",
                    {
                        "name": $("#name").val(),
                        "mobile": $("#mobile").val(),
                        "score": $("#sp_score").html()
                    },
                    function(msg) {
                        if (msg == "0") {
                            layer.open({
                                content: '您已参与过该活动,下次再参与哦!',
                                btn: ['知道了']
                            });
                        } else {
                            layer.open({
                                content: '恭喜您,获得了,'+msg,
                                btn: ['知道了'],
                                end:function(){
                                    location.href="index.html";
                                }
                            });
                        }
                    }    
                );

PHP code

=100) echo "一等奖";
        if($score<100&&$score>=60) echo "二等奖";
        if($score<60) echo "三等奖";
        exit;
    }
}
  
 
?>

Recommended study:《PHP video tutorial

The above is the detailed content of How to add data to database in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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