目标是编码php文件,以便我能够在类别上执行CRUD功能。 我不知道我做错了什么以及为什么我会收到这个错误。检查下面的图片!
但是在更改之后我找不到列:1054未知栏' category_category_id'在'字段列表'在43号线?
第43行
$q->execute(array($category_category_id,$category_name,$id));
updateCategory.php
<?php
require 'database.php';
$id = null;
if ( !empty($_GET['id'])) {
$id = $_REQUEST['id'];
}
if ( null==$id ) {
header("Location: index.php");
}
if ( !empty($_POST)) {
// keep track validation errors
$category_nameError = null;
$category_category_idError = null;
// keep track post values
$category_category_id = $_POST['id'];
$category_name = $_POST['category_name'];
// validate input
$valid = true;
if (empty($category_category_id)) {
$category_idError = 'Please enter Category id';
$valid = false;
}
if (empty($category_name)) {
$category_nameError = 'Please enter Category name';
$valid = false;
}
// update data
if ($valid) {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE category set category_category_id = ?, category_name = ? WHERE id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($category_category_id,$category_name,$id));
Database::disconnect();
header("Location: index.php");
}
} else {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM category where id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($id));
$data = $q->fetch(PDO::FETCH_ASSOC);
$category_category_id = $data['id'];
$category_name = $data['category_name'];
Database::disconnect();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="span10 offset1">
<div class="row">
<h3>Update a Category</h3>
</div>
<form class="form-horizontal" action="updateCategory.php?id=<?php echo $id?>" method="post">
<div class="control-group <?php echo !empty($$category_category_idError)?'error':'';?>">
<label class="control-label">Category Id</label>
<div class="controls">
<input name="id" type="text" placeholder="Category Id" value="<?php echo !empty($category_category_id)?$category_category_id:'';?>">
<?php if (!empty($$category_category_id)): ?>
<span class="help-inline"><?php echo $$category_category_id;?></span>
<?php endif; ?>
</div>
</div>
<div class="control-group <?php echo !empty($category_nameError)?'error':'';?>">
<label class="control-label">Category Name</label>
<div class="controls">
<input name="category_name" type="text" placeholder="Category Name" value="<?php echo !empty($category_name)?$category_name:'';?>">
<?php if (!empty($category_nameError)): ?>
<span class="help-inline"><?php echo $category_nameError;?></span>
<?php endif;?>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Update</button>
<a class="btn" href="index.php">Back</a>
</div>
</form>
</div>
</div> <!-- /container -->
</body>
</html>
的index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<h3>Product Menu</h3>
</div>
<div class="row">
<p>
<a href="create.php" class="btn btn-success">Create</a>
</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Id</th>
<th>CategoryId</th>
<th>Brand</th>
<th>Name</th>
<th>Barcode</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php
include_once 'database.php';
$pdo = Database::connect();
$sql = 'SELECT * FROM product ORDER BY id ASC';
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['category_id'] . '</td>';
echo '<td>'. $row['brand'] . '</td>';
echo '<td>'. $row['name'] . '</td>';
echo '<td>'. $row['barcode'] . '</td>';
echo '<td>'. $row['price'] . '</td>';
echo '<td width=250>';
echo '<a class="btn" href="read.php?id='.$row['id'].'">Read</a>';
echo ' ';
echo '<a class="btn btn-success" href="update.php?id='.$row['id'].'">Update</a>';
echo ' ';
echo '<a class="btn btn-danger" href="delete.php?id='.$row['id'].'">Delete</a>';
echo '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<div class="container">
<div class="row">
<h3>Category Menu</h3>
</div>
<div class="row">
<p>
<a href="createCategory.php" class="btn btn-success">Create</a>
</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Category Id</th>
<th>Category Name</th>
</tr>
</thead>
<?php
include_once 'database.php';
$pdo = Database::disconnect();
$pdo = Database::connect();
$sql = 'SELECT * FROM category ORDER BY id ASC';
foreach ($pdo->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['category_name'] . '</td>';
echo '<td width=250>';
echo '<a class="btn" href="readCategory.php?id='.$row['id'].'">Read</a>';
echo ' ';
echo '<a class="btn btn-success" href="updateCategory.php?id='.$row['id'].'">Update</a>';
echo ' ';
echo '<a class="btn btn-danger" href="deleteCategory.php?id='.$row['id'].'">Delete</a>';
echo '</td>';
echo '</tr>';
}
Database::disconnect();
?>
</tbody>
</table>
</div>
</div>
</body>
</html>
<!-- <div class="container">
<div class="row">
<h3>PHP CRUD Grid</h3>
</div>
<div class="row">
<p>
<a href="create.php" class="btn btn-success">Create</a>
</p>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>CategoryId</th>
<th>Catengory Name</th>
</tr>
</thead>
$sql2 = 'SELECT * FROM category ORDER BY id DESC';
foreach ($pdo->query($sql2) as $row) {
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td>'. $row['category_name'] . '</td>';
echo '<td width=250>';
echo '<a class="btn" href="readCategory.php?id='.$row['id'].'">Read</a>';
echo ' ';
echo '<a class="btn btn-success" href="updateCategory.php?id='.$row['id'].'">Update</a>';
echo ' ';
echo '<a class="btn btn-danger" href="deleteCategory.php?id='.$row['id'].'">Delete</a>';
echo '</td>';
echo '</tr>';
</div>
}
Database::disconnect();
?>
</tbody>
</table> -->
答案 0 :(得分:2)
You need to initialize the variable in the code like this
require 'database.php';
$id = null;
if ( !empty($_GET['id'])) {
$id = $_REQUEST['id'];
}
if ( null==$id ) {
header("Location: index.php");
}
$category_category_id = "";
$category_name = "";
if ( !empty($_POST)) {
// keep track validation errors
$category_nameError = null;
$category_category_idError = null;
// keep track post values
$category_category_id = $_POST['id'];
$category_name = $_POST['category_name'];
// validate input
$valid = true;
if (empty($category_name)) {
$category_nameError = 'Please enter Category name';
$valid = false;
}
if (empty($category_category_id)) {
$category_idError = 'Please enter Category id';
$valid = false;
}
// update data
if ($valid) {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE category set id = ?, category_name = ? WHERE id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($category_category_id,$category_name,$id));
Database::disconnect();
header("Location: index.php");
}
} else {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM category where id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($id));
$data = $q->fetch(PDO::FETCH_ASSOC);
$category_category_id = $data['id'];
$category_name = $data['category_name'];
Database::disconnect();
}
也会更改输入字段名称
<input name = "category_name" id="catogortId" type = "text" placeholder = "Category Name" value = "<?php echo !empty($category_name)?$category_name:'';?>">
答案 1 :(得分:1)
您没有在表单中输入 name 属性值,因此请将其设置为:
<input name="category_name" type="text" placeholder="Category Name" name="category_name" value="<?php echo !empty($category_name)?$category_name:'';?>">
答案 2 :(得分:1)
您没有category_name
字段。
变化:
<input name="category_id" type="text" placeholder="Category Name" value="<?php echo !empty($category_name)?$category_name:'';?>">
要
<input name="category_name" type="text" placeholder="Category Name" value="<?php echo !empty($category_name)?$category_name:'';?>">
答案 3 :(得分:1)
您需要在updateCategory.php文件中将name = "category_name"
更改为<input name = "category_id" type = "text" placeholder = "Category Name" value = "<?php echo !empty($category_name)?$category_name:'';?>">
更改
<input name = "category_name" type = "text" placeholder = "Category Name" value = "<?php echo !empty($category_name)?$category_name:'';?>">
要
function loadPMMLAvailability(algorithmName) {
var status = false;
if (algorithmName) {
$.ajax({
type: "GET",
url: serverUrl + '/api/configs/pmml/' + algorithmName,
success: function (res) {
status = true;
console.log('Im in success');
},
error: function (res) {
status = false;
}
});
}
console.log(status);
return status;
}