为什么数据没有保存在My SQL中?

时间:2018-09-15 01:12:52

标签: php html mysql

我正在使用php开发一个简单的注册表格。

我在这里插入了所有东西,但它并没有进入数据库。

我已经使用了以下文件

  1. register.php:包含表单的界面
  2. connection.php:包含数据库连接信息
  3. form_data_sql_insert.php:为了将值插入到数据库中

但是数据没有插入数据库中

register.php

<html>
    <head>
        <style>
            .bo
            {
                /*background-color:#CCD1D1  ;*/
                text-align: center;
                font-family:"Arial Rounded MT Bold";
                color: #E74C3C;
                font-size: 30px;
                background: url(photos/watch2.jpg);
            }
            input[type=text], select {
                /*width: 100%;*/
                padding: 12px 20px;
                margin: 8px 0;
                display: inline-block;
                border: 1px solid #ccc;
                border-radius: 4px;
                box-sizing: border-box;
            }

            input[type=submit] {
                /*width: 100%;*/
                background-color: #4CAF50;
                color: white;
                padding: 14px 20px;
                margin: 8px 0;
                border: none;
                border-radius: 4px;
                cursor: pointer;
                font-weight: bold;
            }

            input[type=submit]:hover {
                background-color: #45a049;
            }

            div {
                border-radius: 5px;
                background-color: #f2f2f2;
                padding: 20px;
                width: 430px;
                margin-left: auto;
                margin-right:auto;
                text-align: center;
                height: 475px;
                margin-top: -15px;
                opacity: 0.92;
            }

            .pwd {
                width: 209px;
                height: 42px;
                border: 1px solid #ccc;
                border-radius: 4px;
            }

            .lbl {
                font-weight: bold;
            }

            .table {
                margin: 0 auto; /* or margin: 0 auto 0 auto */
                padding-top: 0;
            }
        </style>
    </head>
    <body class="bo">
        <h2>User&nbspRegistration</h2>

        <div>
            <form action="successful.php" method="post">
                <table class="table" >
                    <tr>
                       <td> <label class="lbl" for="fname">First Name</label></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td><input type="text" id="fname" name="firstname" placeholder="First Name"></td>
                    </tr>

                    <tr>
                        <td><label class="lbl" for="lname">Last Name</label></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td><input type="text" id="lname" name="lastname" placeholder="Last Name"></td>
                    </tr>

                    <tr>
                        <td><label class="lbl" for="mobile">Mobile Number</label></td>
                        <td></td>
                        <td></td>
                        <td></td>
                       <td><input type="text" id="mobile" name="mobile" placeholder="Mobile Number"></td>
                    </tr>

                    <tr>
                    <td><label class="lbl" for="mail">Mail Address</label></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    <td><input type="text" id="mail" name="mail" placeholder="Mail Address"></td>
                    </tr>

                    <tr>
                        <td><label class="lbl" for="cardno">Card No</label></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td><input type="text" id="cardno" name="cardno" placeholder="Card No"></td>
                    </tr>

                    <tr>
                    <td><label class="lbl" for="userid">User ID</label></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    <td><input type="text" id="userid" name="userid" placeholder="User ID"></td>
                    </tr>

                    <tr>
                    <td><label class="lbl" for="pwd">Password</label></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    <td><input class="pwd" type="password" id="pwd" name="pwd" readonly></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    <td><input type="checkbox" name="createpwd" value="create"> <span class="lbl">Create</span></td>
                    </tr>

                    <tr>
                        <td style="padding-top: 10px;"><input type="submit" value="Clear"></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td style="padding-left: 126.5px; padding-top: 10px;"><input type="submit" value="Submit" id="submit"></td>
                    </tr>
                </table>


            </form>
        </div>
    </body>
</html>

connection.php

<?php

$connection = mysqli_connect("127.0.0.1","root","","app_registration");

if (!$connection)
{
    $connection_status = 'Connection to database failed';
}
else
{
    $connection_status = null;
    echo "Connected Successfully";
}



**form_data_sql_insert.php**

include ('connection.php');
include ('register.php');
$conn = new mysqli("127.0.0.1","root","","app_registration");

$errors = array();
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mobile = $_POST['mobile'];
$mail = $_POST['mail'];
$card_no = $_POST['cardno'];
$user_id = $_POST['userid'];
$pwd =  $_POST['pwd'];

if(isset($_POST['submit']))
{

    $sql = "INSERT INTO app_user (fname,lname,mobile,mail,card_number,user_id,password) VALUES ('$fname','$lname','$mobile','$mail','$card_no','$pwd')";
    if (!$result = $conn->query($sql)) {
        die('There was an error running the query [' . $conn->error . ']');
    } else {
        echo "Thank you! We will contact you soon";
    }
}
else
{
    echo "error";}

0 个答案:

没有答案