php页面没有向mysql表发送数据

时间:2018-01-05 01:39:13

标签: php mysql

我正在研究html和php表单,它将用户信息存储在mysql表中。 我无法将数据发送到mysql数据库。当我提交表单时,它不会返回任何错误,但同时它不反映对表的任何更改。 这是我的HTML代码。

<form method="post" action="datapost.php">
                    <div class="col-xl-12">
                        <div class="row">
                            <div class="col-sm-6 form-group">
                                <label>First Name</label>
                                <input type="text" placeholder="Enter First Name Here.." name="First_name" class="form-control">
                            </div>
                            <div class="col-sm-6 form-group">
                                <label>Last Name</label>
                                <input type="text" placeholder="Enter Last Name Here.." name="Last_Name" class="form-control">
                            </div>
                        </div>                  
                        <div class="form-group">
                            <label>Address</label>
                            <textarea placeholder="Enter Address Here.." rows="3" name="Address" class="form-control"></textarea>
                        </div>  
                        <div class="row">
                            <div class="col-sm-4 form-group">
                                <label>City</label>
                                <input type="text" placeholder="Enter City Name Here.." name="City" class="form-control">
                            </div>  
                            <div class="col-sm-4 form-group">
                                <label>State</label>
                                <input type="text" placeholder="Enter State Name Here.." class="form-control">
                            </div>  
                            <div class="col-sm-4 form-group">
                                <label>Zip</label>
                                <input type="text" placeholder="Enter Zip Code Here.." name="Zip" class="form-control">
                            </div>      
                        </div>

                    <div class="form-group">
                        <label>Phone Number</label>
                        <input type="text" placeholder="Enter Phone Number Here.." name="Phone_number"class="form-control">
                    </div>      
                    <div class="form-group">
                        <label>Email Address</label>
                        <input type="text" placeholder="Enter Email Address Here.." name="Email" class="form-control">
                    </div>  



            <div class="panel panel-default credit-card-box">
                <div class="panel-heading display-table" >
                    <div class="row display-tr" >
                        <h3 class="panel-title display-td" >Payment Details</h3>
                        <div class="display-td" >                            
                            <img class="img-responsive pull-right" src="http://i76.imgup.net/accepted_c22e0.png">
                        </div>
                    </div>                    
                </div>
                <div class="panel-body">
                    <form role="form" id="payment-form" method="POST" action="javascript:void(0);">
                        <div class="row">
                            <div class="col-xs-12">
                                <div class="form-group">
                                    <label for="cardNumber">CARD NUMBER</label>
                                    <div class="input-group">
                                        <input 
                                            type="tel"
                                            class="form-control"
                                            name="cardNumber"
                                            placeholder="Valid Card Number"
                                            autocomplete="cc-number"
                                            required autofocus 
                                        />
                                        <span class="input-group-addon"><i class="fa fa-credit-card"></i></span>
                                    </div>
                                </div>                            
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-xs-7 col-md-7">
                                <div class="form-group">
                                    <label for="cardExpiry"><span class="hidden-xs">EXPIRATION</span><span class="visible-xs-inline">EXP</span> DATE</label>
                                    <input 
                                        type="tel" 
                                        class="form-control" 
                                        name="cardExpiry"
                                        placeholder="MM / YY"
                                        autocomplete="cc-exp"
                                        required 
                                    />
                                </div>
                            </div>
                            <div class="col-xs-5 col-md-5 pull-right">
                                <div class="form-group">
                                    <label for="cardCVC">CV CODE</label>
                                    <input 
                                        type="tel" 
                                        class="form-control"
                                        name="cardCVC"
                                        placeholder="CVC"
                                        autocomplete="cc-csc"
                                        required
                                    />
                                </div>
                            </div>
                        </div>

                       <!-- <div class="row">
                            <div class="col-xs-12">
                                <button class="subscribe btn btn-success btn-lg btn-block" type="button">Start Subscription</button>
                            </div>
                        </div>-->
                        <button type="submit" class="btn btn-lg btn-info">Submit</button>                   


        <div class="col-xs-12 col-md-4">

                        <div class="row" style="display:none;">
                            <div class="col-xs-12">
                                <p class="payment-errors"></p>
                            </div>
                        </div>
                    </form>
                </div>
            </div>            


        </div>            

我的PHP代码在这里

<?php
include 'databaseconn.php';
$First_name=$_POST['First_name'];
$Last_Name=$_POST['Last_Name'];
$Address=$_POST['Address'];
$City=$_POST['City'];
$Zip=$_POST['Zip'];
$Phone_number=$_POST['Phone_number'];
$Email=$_POST['Email'];
$cardNumber=$_POST['cardNumber'];
$cardExpiry=$_POST['cardExpiry'];
$cardCVC=$_POST['cardCVC'];
mysqli_query($connect, "INSERT INTO user_data (`First_name`,`Last_Name`,`Address`,`City`,`Zip`,`Phone_number`,`Email`,`cardNumber`,`cardExpiry`,`cardCVC`) values ('$First_name','$Last_Name','$Address','$City','$Zip','$Phone_number','$Email','$cardNumber','$cardExpiry','$cardCVC') ");
if(mysqli_affected_rows($connect)>0)
{
    echo'<p> User successfully registered </p>';
    echo'<a href="index.php"> Go BAck </a>';

}
else
{
    echo 'Registration not successfull';
    echo 'mysqli_error($connect)';
}

?>

我的数据库文件在这里。

    <?php
    $servername = "localhost";
    $username = "root";
    $password = "";

    // Create connection
    $connect = mysqli_connect($servername, $username, $password);

    // Check connection
    if (!$connect) {
        die("Connection failed: " . mysqli_connect_error());
    }
    echo "Connected successfully";
    ?>
please someone help me out.

1 个答案:

答案 0 :(得分:-1)

您需要添加数据库名称

$servername = "localhost";
$username = "root";
$password = "";
$database = 'databasename';

// Create connection
$connect = mysqli_connect($servername, $username, $password, $database);