如何通过使用 PHP 在一个文本框中输入输入然后插入到另一个表中来自动从数据库中填充所有输入字段

此代码是在此网站上找到的 https://www.geeksforgeeks.org/how-to-fill-all-input-fields-automatically-from-database-by-entering-input-in-one-textbox-using-php/

我的目标是使用 PHP 在一个文本框中输入输入,然后将其插入另一个表,但它一直失败,请帮助我,从而自动填充数据库中的所有输入字段。

  <html>
    
    <head>
        <script src=
            "https://code.jquery.com/jquery-3.2.1.min.js">
        </script>
    
        <script src=
    "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
            type="text/javascript">
        </script>
        
        <link rel="stylesheet" href=
    "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    
        <script src=
    "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
        </script>
    </head>
    
    <body>
        <div class="container">
            <h1>GeeksForGeeks</h1>
            <div class="row">
                <div class="col-lg-6">
                    <div class="form-group">
                        <label>User Id</label>
                        <input type='text' name="user_id"
                            id='user_id' class='form-control'
                            placeholder='Enter user id'
                            onkeyup="GetDetail(this.value)" value="">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-6">
                    <div class="form-group">
                        <label>First Name:</label>
                        <input type="text" name="first_name"
                            id="first_name" class="form-control"
                            placeholder='First Name'
                            value="">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-6">
                    <div class="form-group">
                        <label>Last Name:</label>
                        <input type="text" name="last_name"
                            id="last_name" class="form-control"
                            placeholder='Last Name'
                            value="">
                    </div>
                </div>
            </div>
        </div>
        <script>
    
            // onkeyup event will occur when the user
            // release the key and calls the function
            // assigned to this event
            function GetDetail(str) {
                if (str.length == 0) {
                    document.getElementById("first_name").value = "";
                    document.getElementById("last_name").value = "";
                    return;
                }
                else {
    
                    // Creates a new XMLHttpRequest object
                    var xmlhttp = new XMLHttpRequest();
                    xmlhttp.onreadystatechange = function () {
    
                        // Defines a function to be called when
                        // the readyState property changes
                        if (this.readyState == 4 &&
                                this.status == 200) {
                            
                            // Typical action to be performed
                            // when the document is ready
                            var myobj = JSON.parse(this.responseText);
    
                            // Returns the response data as a
                            // string and store this array in
                            // a variable assign the value
                            // received to first name input field
                            
                            document.getElementById
                                ("first_name").value = myobj[0];
                            
                            // Assign the value received to
                            // last name input field
                            document.getElementById(
                                "last_name").value = myobj[1];
                        }
                    };
    
                    // xhttp.open("GET","filename",true);
                    xmlhttp.open("GET","gfg.php?user_id=" + str,true);
                    
                    // Sends the request to the server
                    xmlhttp.send();
                }
            }
        </script>
    </body>
    
    </html>
toddfsy001 回答:如何通过使用 PHP 在一个文本框中输入输入然后插入到另一个表中来自动从数据库中填充所有输入字段

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3550.html

大家都在问