2014-04-10 5 views
0

업데이트 쿼리를 만들려고했지만 어떻게해야할지 모르겠다. 내가 생각할 수있는 것은 여기 있지만 작동하지 않을 수도 있습니다. SQL 쿼리에 대해서만 도움이 필요합니다.여러 MySQL 열 업데이트

<?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'); 
} 
?> 

답변

1

준비된 진술이 잘못되었습니다. 자리 표시자를 인용하지 마십시오. 예 :

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

는 대신

INSERT INTO foo (bar) VALUES (?) 

않습니다. DB 엔진이 당신을 위해 모든 인용문을 처리합니다.

+0

일을 웃는 고양이 얼굴'^ - ^' – Dan

+0

IT는 bindvalues ​​수 있을까? – JelloDude

0

수 Tr ? 주위 '"을 제거 :

$query = $pdo->prepare('UPDATE artikler SET artikel_titel = ?, artikel_indhold = ?, sidst_opdateret = ? WHERE artikel_id = ?'); 
+0

작동하지 않았다 : ( – JelloDude

+0

그러나 도움을 주셔서 감사합니다 :) – JelloDude

+0

그것은 bindvalues ​​수 있을까? – JelloDude