程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何使用php将html表单数据插入数据库?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何使用php将html表单数据插入数据库??

开发过程中遇到如何使用php将html表单数据插入数据库?的问题如何解决?下面主要结合日常开发的经验,给出你关于如何使用php将html表单数据插入数据库?的解决方法建议,希望对你解决如何使用php将html表单数据插入数据库?有所启发或帮助;

这段代码看起来一切都很好,但总是无法提交数据,这可能是什么问题?

我正在为 myPHPadmin 数据库使用网络主机 (000webshost)。 该表单曾用于提交数据,但由于某种原因它开始失败,我不明白为什么。 提交表单总是与未能插入数据相呼应,其他一切看起来都不错。 我们在网站前端使用 Tailwind CSS。

这是HTML:

            <div class="container mx-auto flex px-5 py-24 md:flex-row flex-col items-center">
                <div class="lg:w-2/6 md:w-1/2 bg-gray-100 rounded-lg p-8 flex flex-col md:m-auto w-full mt-10 md:mt-0">
                    <form action="insertsite.PHP" method="post">
                        <h2 class="text-gray-900 text-2xl Font-bold Title-Font mb-5">Create POA</h2>
                        <div class="relative mb-4">
                            <h2 class="text-gray-900 text-lg Font-normal Title-Font mb-2">ClIEnt Details</h2>
                            <label for="full-name" class="leading-7 text-sm text-gray-600">Your Full name</label>
                            <input type="text" name="personname"
                                class="w-full bg-white rounded border border-gray-300 focus:border-red-500 focus:ring-2 focus:ring-red-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 Transition-colors duration-200 ease-in-out">
                        </div>
                        <div class="relative mb-4">
                            <label for="email" class="leading-7 text-sm text-gray-600">E-mail</label>
                            <input type="email" name="email"
                                class="w-full bg-white rounded border border-gray-300 focus:border-red-500 focus:ring-2 focus:ring-red-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 Transition-colors duration-200 ease-in-out">
                        </div>
                        <style>
                            input::-webkit-outer-spin-button,input::-webkit-inner-spin-button {
                                -webkit-appearance: none;
                                margin: 0;
                            }
                        </style>
                        <div class="relative mb-4">
                            <label for="Phone" class="leading-7 text-sm text-gray-600">Phone Number</label>
                            <input type="number" name="phone"
                                class="w-full bg-white rounded border border-gray-300 focus:border-red-500 focus:ring-2 focus:ring-red-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 Transition-colors duration-200 ease-in-out">
                        </div>
                        <div class="relative mb-4">
                            <label for="Address" class="leading-7 text-sm text-gray-600">Enter Your Address</label>
                            <input type="Address" name="address"
                                class="w-full bg-white rounded border border-gray-300 focus:border-red-500 focus:ring-2 focus:ring-red-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 Transition-colors duration-200 ease-in-out">
                        </div>
                        <div class="relative mb-4">
                            <label for="aadhaar" class="leading-7 text-sm text-gray-600">Enter Your aadhaar Number</label>
                            <input type="number" name="aadharnumber"
                                class="w-full bg-white rounded border border-gray-300 focus:border-red-500 focus:ring-2 focus:ring-red-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 Transition-colors duration-200 ease-in-out">
                        </div>
                        <div class="relative mb-4">
                            <label for="PanNo" class="leading-7 text-sm text-gray-600">Enter Your Pan Number</label>
                            <input type="text" name="panno"
                                class="w-full bg-white rounded border border-gray-300 focus:border-red-500 focus:ring-2 focus:ring-red-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 Transition-colors duration-200 ease-in-out">
                        </div>
                        <h2 class="text-gray-900 text-lg Font-normal Title-Font mt-4 mb-2">ClIEnt Bank Details</h2>
                        <div class="relative mb-4">
                            <label for="Bankname" class="leading-7 text-sm text-gray-600">Enter name of Your Bank</label>
                            <input type="text" name="bankname"
                                class="w-full bg-white rounded border border-gray-300 focus:border-red-500 focus:ring-2 focus:ring-red-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 Transition-colors duration-200 ease-in-out">
                        </div>
                        <div class="relative mb-4">
                            <label for="BankBranch" class="leading-7 text-sm text-gray-600">Enter name of Your Bank's branch</label>
                            <input type="text" name="branchname"
                                class="w-full bg-white rounded border border-gray-300 focus:border-red-500 focus:ring-2 focus:ring-red-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 Transition-colors duration-200 ease-in-out">
                        </div>
                        <div class="relative mb-4">
                            <label for="Holdername" class="leading-7 text-sm text-gray-600">Enter Account Holders name</label>
                            <input type="text" name="accholder"
                                class="w-full bg-white rounded border border-gray-300 focus:border-red-500 focus:ring-2 focus:ring-red-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 Transition-colors duration-200 ease-in-out">
                        </div>
                        <div class="relative mb-4">
                            <label for="AccNumber" class="leading-7 text-sm text-gray-600">Enter Account Number</label>
                            <input type="text" name="accno"
                                class="w-full bg-white rounded border border-gray-300 focus:border-red-500 focus:ring-2 focus:ring-red-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 Transition-colors duration-200 ease-in-out">
                        </div>
                        <div class="relative mb-4">
                            <label for="IFSC" class="leading-7 text-sm text-gray-600">Enter The IFSC Code</label>
                            <input type="text" name="ifsc"
                                class="w-full bg-white rounded border border-gray-300 focus:border-red-500 focus:ring-2 focus:ring-red-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 Transition-colors duration-200 ease-in-out">
                        </div>
                        <div class="relative mb-4">
                            <label for="UPI" class="leading-7 text-sm text-gray-600">Enter UPI ID</label>
                            <input type="text" name="upi"
                                class="w-full bg-white rounded border border-gray-300 focus:border-red-500 focus:ring-2 focus:ring-red-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 Transition-colors duration-200 ease-in-out">
                        </div>
                        <button type="submit" name="submit"
                            class="text-white bg-red-500 border-0 py-2 px-8 focus:outline-none hover:bg-red-600 rounded text-lg">Save Your Data</button>
                    </form>
                </div>
            </div>
    </section>

这是 PHP:

    $server = "localhost" ;
    $username = "removed";
    $password = "removed";
    $dbname = "ID16235805_portfolio";
    $con = MysqLi_connect($server,$username,$password,$dbname );
    
    if(isset($_POST['submit'])) {
        $personname = $_POST["personname"];
        $email = $_POST["email"];
        $phone =$_POST["phone"];
        $address =$_POST["address"];
        $aadharnumber =$_POST["aadharnumber"];
        $panno =$_POST["panno"];
        $bankname =$_POST["bankname"];
        $branchname =$_POST["branchname"];
        $accholder =$_POST["accholder"];
        $accno =$_POST["accno"];
        $upi =$_POST["upi"];
        $brokerage =$_POST["brokerage"];
        $periodofagr =$_POST["periodofagr"];
        $amountrecIEved =$_POST["amountrecIEved"];
        $amountrecinwords =$_POST["amountrecinwords"];
        $accopeningchar =$_POST["accopeningchar"];
        $lockingperiod =$_POST["lockingperiod"];
        $clIEntage =$_POST["clIEntage"];
        $payback =$_POST["payback"];
        $ifsc =$_POST["ifsc"];
        $daterec =$_POST["daterec"];
        $startingdate =$_POST["startingdate"];
        $endingdate =$_POST["endingdate"];
        
    
        $sql = "INSERT INTO clIEnt_details (personname,email,phone,address,aadharnumber,panno,bankname,branchname,accholder,accno,upi,brokerage,periodofagr,amountrecIEved,amountrecinwords,accopeningchar,lockingperiod,clIEntage,payback,ifsc,daterec,startingdate,endingdate) VALUES ('$personname','$email','$phone','$address','$aadharnumber','$panno','$bankname','$branchname','$accholder','$accno','$upi','$brokerage','$periodofagr','$amountrecIEved','$amountrecinwords','$accopeningchar','$lockingperiod','$clIEntage','$payback','$ifsc','$daterec','$startingdate','$endingdate')";
        
        $result = MysqLi_query( $con,$sql );
        
        
        if($result) {
            echo "Data Inserted";
        }
        else {
            echo "Failed to Insert Data";
        }
    }
?>```


Please look into the code above and see if there is any type of error.
Iam updating the same db from androID app and another smaller HTML form and it works but for this bigger one it is failing.

解决方法

你的整个代码看起来不错。由于此代码曾经运行良好,请确保任何输入框都没有键入特殊字符,例如“/”,如果是,则必须使用 mysqli_real_escape_string($connection,$输入框值)。干杯!

大佬总结

以上是大佬教程为你收集整理的如何使用php将html表单数据插入数据库?全部内容,希望文章能够帮你解决如何使用php将html表单数据插入数据库?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: