gpt4 book ai didi

php - 更新多个 MySQL 列

转载 作者:行者123 更新时间:2023-11-29 13:03:49 24 4
gpt4 key购买 nike

我尝试进行更新查询,但我不知道该怎么做。这是我认为可能有效的方法,但事实并非如此。我只需要 SQL 查询方面的帮助。

<?php
session_start();
include_once ('../includes/connection.php');
include_once ('../includes/article.php');
$artikel = new Artikel;
if (isset($_SESSION['logged_in'])) {
if (isset($_GET['id'])) {
$titel = $_POST['titel'];
$indhold = $_POST['indhold'];
$id = $_GET['id'];
$query = $pdo->prepare('UPDATE artikler SET artikel_titel = "?", artikel_indhold = "?", sidst_opdateret = "?" WHERE artikel_id = ?');
$query->bindValue(1, $titel);
$query->bindValue(2, $indhold);
$query->bindValue(3, time());
$query->bindValue(4, $id);
$query->execute();
header('location: index.php');
}
$artikler = $artikel->fetch_all();
if (empty($titel) or empty($indhold)) {
$error = 'Alle felter skal udfyldes';
} else {
$query = $pdo->prepare('INSERT INTO artikler (artikel_titel, artikel_indhold, sidst_opdateret) VALUES (?, ?, ?)');
$query->bindValue(1, $titel);
$query->bindValue(2, $indhold);
$query->bindValue(3, time());
$query->execute();
header('location: index.php');
}
?>
<html>
<head>
<meta charset="UTF-8">
<title>Ændre side</title>
<link rel="stylesheet" href="../assets/style.css">
<link rel="shortcut icon" href="/billeder/book.png">
</head>
<body>
<div class="container">

<h4>Ændre side</h4>
<br>
<form action="edit.php" method="get">
<select name="id">
<?php foreach($artikler as $artikel) { ?>
<option value="<?php echo $artikel['artikel_id']; ?>">
<?php echo $artikel['artikel_titel']; ?>
</option>
<?php } ?>
</select>
<br>
<input type="text" name="titel" placeholder="Ny Titel">
<br>
<textarea name="indhold" cols="50" rows="15" placeholder="Indhold"><?php echo $artikel['artikel_indhold']; ?></textarea>
<br>
<input type="submit" value="Ændre">
</form>
<a href="index.php" id="logo">&larr;Tilbage</a>
</div>
</body>
</html>
<?php
} else {
header('location: index.php');
}
?>

最佳答案

您准备的陈述不正确。您不引用占位符。例如

INSERT INTO foo (bar) VALUES ('?')
^-^--- incorrect

你愿意

INSERT INTO foo (bar) VALUES (?)

相反。数据库引擎将为您处理所有引用。

关于php - 更新多个 MySQL 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22994260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com