Cześć mam problem odnośnie edycji formularza, czy da rade zmienić wartość inputa typu file?
<?php
require 'database.php';
$id = null;
if(!empty($_GET['id'])){
$id = $_GET['id'];
$pdo = Database::connect();
$sql = "SELECT * from attractions where attractions.id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($id));
$data = $q->fetch(PDO::FETCH_ASSOC);
$name = $data['name'];
$price = $data['price'];
$countries_id = $data['countries_id'];
$description = $data['description'];
}
if($id == null){
header("Location: index.php");
}
if(!empty($_POST)){
$name = $_POST['name'];
$price = $_POST['price'];
$countries_id = $_POST['countries_id'];
$description = $_POST['description'];
$image = $_POST['image'];
var_dump($_POST);
$pdo = Database::connect();
$sql = "UPDATE attractions set name = :name, price = :price, countries_id = :countries_id, description = :description, image = :image, WHERE attractions.id = :id";
$q = $pdo->prepare($sql);
$q->bindValue('name', $name, PDO::PARAM_STR);
$q->bindValue('price', $price, PDO::PARAM_INT);
$q->bindValue('countries_id', $countries_id, PDO::PARAM_INT);
$q->bindValue('description', $description, PDO::PARAM_STR);
$q->bindValue('image', $image, PDO::PARAM_STR);
$q->bindValue('id', $id, PDO::PARAM_INT);
$q->execute();
var_dump($data);
Database::disconnect();
// sprawdzamy czy wywołanie execute() się udało
$error = $q->errorInfo();
if ($error[0]) {
var_dump($error);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row">
<h1>Edycja atrakcji</h1>
</div>
<form class="row" action="edit.php?id=<?php echo $id; ?>" method="post">
<label>Nazwa</label>
<input name="name" type="text" placeholder="name" value="<?php echo $name; ?>"><br />
<label>Cena</label>
<input name="price" type="text" placeholder="price" value="<?php echo $price; ?>"><br />
<label>Gatunek</label>
<select name="countries_id" value="<?= $data['countries_id'] ?>">
<?php
$pdo = Database::connect();
$sqlcountry = "SELECT * FROM countries";
foreach($pdo->query($sqlcountry) as $row){
if($row['id']==$countries_id){$selected='selected';}else{$selected='';}
echo '<option value="' . $row["id"] . '" '.$selected.'>' . $row["name"] . '</option>';
}
Database::disconnect();
?>
</select><br/>
<label>Opis</label>
<input name="description" type="text" placeholder="description" value="<?php echo $description; ?>"><br />
<input type="file" name="plik" value="aktywacja.png"/><br/>
<button type="submit" class="btn btn-success">Zapisz</button>
<a class="btn" href="index.php">Powrot</a>
</form>
</div> <!-- /container -->
</body>
</html>
Zrobiłem cos takiego a bład mam taki:
Notice: Undefined index: image in C:\xampp\htdocs\crude projekt\edit.php on line 25
array(5) { ["name"]=> string(4) "Abob" ["price"]=> string(3) "234" ["countries_id"]=> string(1) "2" ["description"]=> string(37) "Fajna miejscowka na grilla za torami." ["plik"]=> string(8) "pnb5.png" } array(9) { ["id"]=> string(1) "5" ["name"]=> string(4) "Abob" ["description"]=> string(37) "Fajna miejscowka na grilla za torami." ["image"]=> string(6) "ATTR05" ["countries_id"]=> string(1) "2" ["food"]=> string(3) "123" ["drive"]=> string(3) "224" ["insurance"]=> string(3) "556" ["price"]=> string(3) "234" } array(3) { [0]=> string(5) "42000" [1]=> int(1064) [2]=> string(174) "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE attractions.id = '5'' at line 1" }
Jak inaczej do tego się zabrac?? Dziękuje z góry za pomoc :)