我试图添加另一个字段名称“hospital_name”。每次我添加一些字段并尝试添加新记录时,它总是失败并且不会出现在我的列表中。
以下是添加记录的代码
<?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!";
}
&GT;
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 :(得分:0)
你的MySQL查询没有医院专栏。以下查询应该有医院名称栏
$query = "INSERT INTO users(first_name, last_name, email, work, MISSING_COLUMN) VALUES('$first_name', '$last_name', '$email', '$work', '$hospital_name')";