Php 添加图像文件时的数组到字符串转换
尝试添加图像文件时出现此错误 警告:第10行C:\xampp\htdocs\ecom\sav_p.php中的数组到字符串转换 这是我的代码:Php 添加图像文件时的数组到字符串转换,php,sql,database,file,pdo,Php,Sql,Database,File,Pdo,尝试添加图像文件时出现此错误 警告:第10行C:\xampp\htdocs\ecom\sav_p.php中的数组到字符串转换 这是我的代码: `<?php require_once 'header.php'; require_once 'connect.php'; $stmt = $conn->prepare('SELECT * FROM `categories`'); $stmt->execute(); $categor
`<?php
require_once 'header.php';
require_once 'connect.php';
$stmt = $conn->prepare('SELECT * FROM `categories`');
$stmt->execute();
$categories = $stmt->fetchAll();`
`?>
<div class="container pt-5 mt-5">
<div class="row">
<div class="col-lg-5">
<h4>Ajouter une nouvelle categorie</h4>
<form action="save.php" class="form-group" method="post">
<label for="">Nom de la categorie</label>
<input type="text" name="name" class="form-control" placeholder="Nom de la categorie"
required>
<label for="">Image de la categorie</label>
<input type="file" class="form-control-file">
<button type="submit" class="btn btn-primary">Enregistrer</button>
</form>
</div>
<div class="col-lg-5">
<h4>Ajouter un produit</h4>
<form action="sav_p.php" class="form-group" method="post" enctype="multipart/form-data">
<label for="">Nom du produit</label>
<input type="text" name="nom" class="form-control" placeholder="Nom du produit" required>
<label for="">Image du produit</label>
<input type="file" class="form-control-file" name="img">
<label for="">description du produit</label>
<input type="text" name="description" class="form-control" placeholder="description du
produit">
<label for="">prix du produit</label>
<input type="text" name="prix" class="form-control" placeholder="prix du produit"
required>
<select class="form-control" id="exampleFormControlSelect1" name="categorie">
<?php
foreach ($categories as $categorie) {
?>
<option value="<?php echo $categorie['id']; ?>"><?php echo $categorie['name']; ?>
</option>
<?php }?>
</select>
<button type="submit" class="btn btn-primary">Enregistrer</button>
</form>
</div>
</div>
</div>`
` <?php
require_once 'footer.php';
require_once 'connect.php';
$stmt=$conn->prepare('INSERT INTO `products` (img, nom , description, prix, categorie)
values(?,?,?,?,?)');
$stmt->execute([
$_FILES['img'],
$_POST['nom'],
$_POST['description'],
$_POST['prix'],
$_POST['categorie']
]);`
$\u文件['img']
是一个数组。你打算从里面取文件名吗?
1 id Primaire int(11) Non Aucun(e) AUTO_INCREMENT
2 nom varchar(250) utf8mb4_general_ci Non Aucun(e)
3 img varchar(2080) utf8mb4_general_ci Non Aucun(e)
4 description varchar(250) utf8mb4_general_ci Oui NULL
5 prix varchar(250) utf8mb4_general_ci Non Aucun(e)