我认为我做了一个错误的mysqli查询,因为数据没有插入数据库,我试图找到错误,但我不能。你能帮帮我吗我也尝试用rapidphp找到错误,但它没有用。
多数民众赞成我的PHP:
if(isset($_POST['addclient']))
{
$name = $_POST['name'];
$last = $_POST['last'];
$email = $_POST['email'];
$password = $_POST['password'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$hosting = $_POST['hosting'];
$hosting_name = $_POST['hosting_name'];
$hosting_password = $_POST['hosting_password'];
$registration = $_POST['registration'];
$notes = $_POST['notes'];
// checking empty fields
if(empty($email)) {
if(empty($email)) {
echo "<div class='alert alert-danger alert-dismissable'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
<center>Something went wrong.. </center>
</div>";
}
} else {
$result = mysqli_query($conn, "INSERT INTO clients (name,last,email,password,address,phone,hosting,hosting_name,hosting_password,registration,notes)
VALUES('$name','$last','$email','$password','$address','$phone','$hosting','$hosting_name','$hosting_password',now(),'$notes')");
echo"<div class='alert alert-success alert-dismissable'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
<center>Client successfully updated..</center>
</div>";
}
}
我还检查了HTML表单,它似乎工作正常。
答案 0 :(得分:0)
在你的mysqli_query中你提到了'registration'数据库字段名 但是你没有把你所采用的文本框引用放在变量中 $ registration = $ _POST ['registration']; 我也检查你的代码它工作正常,你应该检查你的 DataBase连接文件。
这是我的数据库连接文件:
<?php
$con=mysqli_connect('localhost','root','','stackoverflow');
if($con)
{
echo ".";
}
else
{
echo "not connected";
}
?>
<?php
include('connection.php');
if(isset($_POST['addclient']))
{
$name = $_POST['name'];
$last = $_POST['last'];
$email = $_POST['email'];
$password = $_POST['password'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$hosting = $_POST['hosting'];
$hosting_name = $_POST['hosting_name'];
$hosting_password = $_POST['hosting_pass'];
$registration = $_POST['registration'];
$notes = $_POST['notes'];
if(empty($email))
{
if(empty($email))
{
echo "<div class='alert alert-danger alert-dismissable'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
<center>Something went wrong.. </center>
</div>";
}
}
else
{
$result = mysqli_query($con, "INSERT INTO clientdata (name,last,email,password,address,phone,hosting,hosting_name,hosting_password,registration,notes)
VALUES('$name','$last','$email','$password','$address','$phone','$hosting','$hosting_name','$hosting_password',now(),'$notes')");
echo "<div class='alert alert-success alert-dismissable'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
<center>Client successfully updated..</center>
</div>";
}
}
?>
<html>
<head>
<title>client data</title>
<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.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="containar">
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4">
<form method="post" class="form-group">
<label >Enter FirstName:</label>
<input type="text" class="form-control" name="name" placeholder="Enter Name..."><br><br>
<label >Enter LastName:</label>
<input type="text" class="form-control" name="last" placeholder="Enter LastName"><br><br>
<label >Enter Email Address:</label>
<input type="email" class="form-control" name="email" placeholder="Enter Email..."><br><br>
<label >Enter Password:</label>
<input type="password" class="form-control" name="password" placeholder="Enter Password..."><br><br>
<label >Enter Address:</label>
<textarea placeholder="Enter Address..." class="form-control" name="address" style="width:430px;
height:100"></textarea> <br><br>
<label >Enter Mobile Number:</label>
<input type="number" class="form-control" name="phone" placeholder="Enter Phone Number..."><br><br>
<label >Enter Hosting:</label>
<input type="text" class="form-control" name="hosting" placeholder="Enter Hosting..."><br><br>
<label >Enter Hosting Name:</label>
<input type="text" class="form-control" name="hosting_name" placeholder="Enter HostingName..."><br><br>
<label >Enter Hosting Password:</label>
<input type="password" class="form-control" name="hosting_pass" placeholder="Enter Hosting Password..."><br><br>
<label >Enter Registration:</label>
<input type="text" class="form-control" name="registration" placeholder="Enter Registration..."><br><br>
<label >Enter Notes:</label>
<input type="text" class="form-control" name="notes" placeholder="Enter Notes...">
<br><br>
<input type="submit" name="addclient" value="submit" class="class">
</div>
<div class="col-md-4"></div>
</div>
</div>
</form>
</body>
</html>