我想将数据从html表单上传到数据库,下面是我的html代码:
<form method="post" action="events.php" id="formhh" enctype="multipart/form-data">
<input type="text" name="Titre" required>
<input type="file" accept="image/jpeg" name="Image" required>
<textarea name="Description" form="formhh" required></textarea>
<div>
<input type="radio" name="style" value="1" required>
<input type="radio" name="style" value="2" required>
<input type="radio" name="style" value="3" required>
<input type="radio" name="style" value="4" required>
<input type="radio" name="style" value="5" required>
</div>
<input type="submit" class="btn btn-outline-primary me-5">
</form>以及连接数据并将数据发送到数据库的"events.php“(名为”connects“):
<?php
$conn = new mysqli("localhost", "root", "", "isticg");
$Titre = $_POST['Titre'];
$Img = mysqli_real_escape_string($conn ,file_get_contents($_FILES['Image']['tmp_name']));
$Desc = $_POST['Description'];
$Style = $_POST['style'];
$stmt = $conn->prepare("insert into evenements(Titre, Image, Description,style) values(?,?,?,?)");
$stmt->bind_param("sbsi",$Titre,$Img,$Desc,$Style);
$stmt->execute();
$stmt->close();
$conn->close();
?>除了图像,一切都很好,下面是做完测试后,它在phpmyadmin中的外观如何?
我是一个初学者,刚刚开始学习这个项目的php,所以请您提供一个解释与您的答案。
发布于 2022-04-09 19:53:19
修好了!我将php代码更改为:
<?php
$dbh = new PDO("mysql:host=localhost;dbname=isticg", "root", "");
$Titre = $_POST['Titre'];
$Img = file_get_contents($_FILES['Image']['tmp_name']);
$Desc = $_POST['Description'];
$Style = $_POST['style'];
$stmt = $dbh->prepare("insert into evenements values('',?,?,?,?)");
$stmt->bindParam(1,$Titre);
$stmt->bindParam(2,$Img);
$stmt->bindParam(3,$Desc);
$stmt->bindParam(4,$Style);
$stmt->execute();
?>https://stackoverflow.com/questions/71810856
复制相似问题