为什么我不能使用PHP和HTML将数据保存到MySQL数据库?

时间:2015-05-20 19:01:20

标签: php html mysql

为什么我无法将数据保存到数据库?我手动检查每行代码,但没有任何内容抛给数据库。另一件事它没有显示任何错误。

最后一次它还在工作但在我将<input type= text name=firstname...>附加到<div></div>以及其他输入文本之后......最终没有任何事情发生..

<!-- language_php-->
<?php
define('DB_SERVER', 'localhost'); 
define('DB_USERNAME', 'user');
define('DB_PASSWORD', 'pass');
define('DB_DATABASE', 'project');
$connection = @mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if(isset($_POST['pawnshopName'])&&isset($_POST['street'])&&isset($_POST['barangay'])&&isset($_POST['city'])&&isset($_POST['dtiPermitNo'])&&isset($_POST['mayorPermitNo'])&&isset($_POST['firstName'])&&isset($_POST['lastName'])&&isset($_POST['middleName'])&&isset($_POST['contactNumber'])&&isset($_POST['email'])&&isset($_POST['password']))
            {
$pawnshopName = $_POST['pawnshopName'];
$street = $_POST['street'];
$barangay = $_POST['barangay'];
$city = $_POST['city'];
$dtiPermitNo = $_POST['dtiPermitNo'];
$mayorPermitNo = $_POST['mayorPermitNo'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$middleName = $_POST['middleName'];
$contactNumber = $_POST['contactNumber'];
$email = $_POST['email'];
$password = $_POST['password'];

$sql = "INSERT INTO pawnshop ".
"(Pawnshop_ID, Pawnshop_Name, Street, Barangay, City, DTI_Permit_No, Mayor_Permit_No, Firstname, Middlename, Lastname, Contact_Number, Email_Address, Password) ".
"VALUES ".
"('','".$pawnshopName."', '".$street."', '".$barangay."', '".$city."', '".$dtiPermitNo."', '".$mayorPermitNo."', '".$firstName."', '".$lastName."', '".$middleName."', '".$contactNumber."', '".$email."', '".$password."' )";

$retval = mysqli_query($connection, $sql);
if(!$retval)
{
die('could not enter data' . mysqli_error($connection));
}
echo "Data Successfully Entered\n";
mysqli_close($connection);
}
?>
<!--language_html-->            
<html>
<head>
    <meta charset="utf-8">
<title>Registration</title>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/custom.css">
</head>
<body>
    <nav class="navbar navbar-custom navbar-fixed-top" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <p class="systemName">cc</p>
            </div>
            <div class="register" align="right"><a href="#" class="textRegister">Login</a> </div>
        </div>
    </nav>
    <br><br><br><br><br><br><br>
    <div class="row  pad-top">
        <div class="col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <strong>   Register to PBMS Account</strong>  
                </div>
                <div class="panel-body">
                    <form action="" method="post">
                    <br/>
                    <i class="req">* All fields are required.</i>
                    <div class="form-group">//Maybe this div causes the error...
                        <span class="input-group-addon">
                        <input type="text" name="firstName" class="form-control" placeholder="First Name" /></span>

                    </div>
                    <div class="form-group">//Maybe this div causes the error...
                        <span class="input-group-addon">
                        <input type="text" name="middleName" class="form-control" placeholder="Middle Name" /></span>
                    </div>
                    <div class="form-group">//Maybe this div causes the error...
                        <span class="input-group-addon">
                        <input type="text" name="lastName" class="form-control" placeholder="Last Name" /></span>
                    </div>
                    <center>Business Information <br></center>
                    <div class="form-group">//Maybe this div causes the error...
                        <span class="input-group-addon">
                        <input type="text" name="businessName" class="form-control" placeholder="Business Name" /></span>
                    </div>
                    <div class="form-group">//Maybe this div causes the error...
                        <span class="input-group-addon">
                        <input type="text" name="street" class="form-control" placeholder="Street" /></span>
                    </div>
                    <div class="form-group">//Maybe this div causes the error...
                        <span class="input-group-addon">
                        <input type="text" name="barangay" class="form-control" placeholder="Barangay" /></span>    
                    </div>
                    <div class="form-group">//Maybe this div causes the error...
                        <span class="input-group-addon">
                        <input type="text" name="city" class="form-control" placeholder="City" /></span>
                    </div>
                    <center>Business Permit <br></center>
                    <div class="form-group">//Maybe this div causes the error...
                        <span class="input-group-addon">
                        <input type="text" name="dtiPermitNo" class="form-control" placeholder="DTI Permit No." /></span>                                    
                    </div>
                    <div class="form-group">//Maybe this div causes the error...
                        <span class="input-group-addon">
                        <input type="text" name="mayorPermitNo" class="form-control" placeholder="Mayor's Permit No." /></span>                                    </form>
                    </div>
                    <center>Account <br></center>
                    <div class="form-group">//Maybe this div causes the error...
                        <span class="input-group-addon">
                        <input type="text" name="email" class="form-control" placeholder="Your Email" /></span>
                    </div>
                    <div class="form-group">//Maybe this div causes the error...
                        <span class="input-group-addon">
                        <input type="password" name="password" class="form-control" placeholder="Enter Password" /></span>                                    </form>
                    </div>
                    <button class="btn btn-success" type="submit">Register</button>
                    </form>
                </div>
                </div>
            </div>
        </div>
        <br><br><br><br><br><br>
        <footer>
        <center>cc 2015.</center>
        </footer>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您正在检查是否设置了$ _POST ['pawnshopName'],而不是。您应该将其更改为$ _POST ['businessName']。或者,您可以使用name =“businessName”将输入字段更改为name =“pawnshopName”。