2017-05-28 11 views
1

別のフィールド名 "hospital_name"を追加しようとしています。いくつかのフィールドを追加して新しいレコードを追加しようとするたびに、常に失敗し、私のリストには表示されません。シンプルクルードAJAX/JQUERYを使用

ここで追加録音

<?php 
if(isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['email']) && isset($_POST['work']) && isset($_POST['hospital_name'])) 
{ 
    // include Database connection file 
    include("db_connection.php"); 

    // get values 
    $first_name = $_POST['first_name']; 
    $last_name = $_POST['last_name']; 
    $email = $_POST['email']; 
    $work = $_POST['work']; 
    $hospital_name = $_POST['hospital_name']; 

    $query = "INSERT INTO users(first_name, last_name, email, work) VALUES('$first_name', '$last_name', '$email', '$work', '$hospital_name')"; 
    if (!$result = mysql_query($query)) { 
     exit(mysql_error()); 
    } 
    echo "1 Record Added!"; 
} 

?>

Updateuserdetailコード

<?php 
// include Database connection file 
include("db_connection.php"); 

// check request 
if(isset($_POST)) 
{ 
    // get values 
    $id = $_POST['id']; 
    $first_name = $_POST['first_name']; 
    $last_name = $_POST['last_name']; 
    $email = $_POST['email']; 
    $work = $_POST['work']; 
    $hospital_name = $_POST['hospital_name']; 
    // Updaste User details 
    $query = "UPDATE users SET first_name = '$first_name', last_name = '$last_name', email = '$email', work = '$work', hospital_name = '$hospital_name' 
    WHERE id = '$id'"; 
    if (!$result = mysql_query($query)) { 
     exit(mysql_error()); 
    } 
} 

ためのコードの私scriptjs

// Add Record 
function addRecord() { 
    // get values 
    var first_name = $("#first_name").val(); 
    var last_name = $("#last_name").val(); 
    var email = $("#email").val(); 
    var work = $("#work").val(); 
    var hospital_name = $("#hospital_name").val(); 
    // Add record 
    $.post("ajax/addRecord.php", { 
     first_name: first_name, 
     last_name: last_name, 
     email: email, 
     work: work, 
     hospital_name: hospital_name 
    }, function (data, status) { 
     // close the popup 
     $("#add_new_record_modal").modal("hide"); 

     // read records again 
     readRecords(); 

     // clear fields from the popup 
     $("#first_name").val(""); 
     $("#last_name").val(""); 
     $("#email").val(""); 
     $("#work").val(""); 
     $("#hospital_name").val(""); 
    }); 
} 

// READ records 
function readRecords() { 
    $.get("ajax/readRecords.php", {}, function (data, status) { 
     $(".records_content").html(data); 
    }); 
} 


function DeleteUser(id) { 
    var conf = confirm("Are you sure, do you really want to delete User?"); 
    if (conf == true) { 
     $.post("ajax/deleteUser.php", { 
       id: id 
      }, 
      function (data, status) { 
       // reload Users by using readRecords(); 
       readRecords(); 
      } 
     ); 
    } 
} 

function GetUserDetails(id) { 
    // Add User ID to the hidden field for furture usage 
    $("#hidden_user_id").val(id); 
    $.post("ajax/readUserDetails.php", { 
      id: id 
     }, 
     function (data, status) { 
      // PARSE json data 
      var user = JSON.parse(data); 
      // Assing existing values to the modal popup fields 
      $("#update_first_name").val(user.first_name); 
      $("#update_last_name").val(user.last_name); 
      $("#update_email").val(user.email); 
      $("#update_work").val(user.work); 
      $("#update_hospital_name").val(user.hospital_name); 
     } 
    ); 
    // Open modal popup 
    $("#update_user_modal").modal("show"); 
} 

function UpdateUserDetails() { 
    // get values 
    var first_name = $("#update_first_name").val(); 
    var last_name = $("#update_last_name").val(); 
    var email = $("#update_email").val(); 
    var work = $("#update_work").val(); 
    var work = $("#update_hospital_name").val(); 

    // get hidden field value 
    var id = $("#hidden_user_id").val(); 

    // Update the details by requesting to the server using ajax 
    $.post("ajax/updateUserDetails.php", { 
      id: id, 
      first_name: first_name, 
      last_name: last_name, 
      email: email, 
      work: work, 
      update_hospital_name 
     }, 
     function (data, status) { 
      // hide modal popup 
      $("#update_user_modal").modal("hide"); 
      // reload Users by using readRecords(); 
      readRecords(); 
     } 
    ); 
} 

$(document).ready(function() { 
    // READ recods on page load 
    readRecords(); // calling function 
}); 

モーダル行を追加です
<div class="form-group"> 
       <label for="hospital_name">hospital name</label> 
       <input type="text" id="hospital_name" placeholder="hospital name" class="form-control"/> 
      </div> 

更新ユーザーモーダル

<div class="form-group"> 
        <label for="update_hospital_name">Hospital Name</label> 
        <input type="text" id="update_hospital_name" placeholder="Hospital Name" class="form-control"/> 
       </div> 
+0

私のデータベースにいくつかのデータを手動で追加しようとしました。 – lenewb

答えて

0

あなたはMySQLのクエリは、病院の列を持っていません。以下のクエリは病院の名前の列を持っている必要があります

$query = "INSERT INTO users(first_name, last_name, email, work, MISSING_COLUMN) VALUES('$first_name', '$last_name', '$email', '$work', '$hospital_name')"; 
+0

ありがとうございました!ホーリー!痛みの5時間後にハハ – lenewb

+0

ハハ.. 5時間?真剣に?!?申し訳ありませんが、愚かな誤りでした。とにかく、前に幸運。 :) この質問にチェックを入れ、投票して閉じることができます。 –

+0

私のjsコードをretweakしようとしました。ああ!どうもありがとうございます! – lenewb

関連する問題