2017-11-05 4 views
0

データがDBに挿入されていないので間違ったmysqliクエリを実行したと思いますが、間違いを見つけようとしましたができませんでした。あなたは私を助けてくれますか?私はrapidphpで間違いを見つけようとしましたが、うまく動作しませんでした。私のPHPザッツmysqliクエリが間違っていますか?

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'>&times;</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'>&times;</button> 
           <center>Client successfully updated..</center> 
          </div>"; 
    } 
} 

私はまた、HTMLは、それが正常に動作しているようだ形成にチェック。

答えて

0

あなたのmysqli_queryに「登録」データベースフィールド名 がありましたが、あなたが取ったテキストボックス参照を変数 $ 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'>&times;</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'>&times;</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> 
関連する問題