php - 如何将图像添加到php mysql数据库?

标签 php mysql database image

我有这个数据库添加页面,它允许您向数据库添加更多对象,并且工作正常,但我需要条目附加图像,但无法使其工作。下面是我当前的工作解决方案(- 图像),我需要添加什么才能使其能够将图像上传到条目。这些变量是芬兰语,因为这是我需要使用最终产品的语言,所以不用介意它们。

这是布局图片

添加页面:http://imgur.com/7y9mjoc

显示数据库中所有内容的索引页:http://imgur.com/jwYbZZT

 <?php
$mysqli = new mysqli(---); // I put in lines to protect my personal info
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$Tyyppi = $_POST["tyyppi"];
$Malli = $_POST["malli"];
$Sarjanumero = $_POST["sarjanum"];
$Paikka = $_POST["paikka"];
$Kuvaus = $_POST["kuvaus"];
$Lainassa = $_POST["laina"];
$Lainaaja = $_POST["lainaaja"];
$Puhelin = $_POST["puhelin"];
$Sposti = $_POST["sposti"];
$Palautus = $_POST["palautus"];

if ($Lainassa==1){
if ($stmt = $mysqli->prepare("INSERT laitteet (tyyppi, malli, sarjanumero, paikka, kuvaus, lainassa, lainaaja, puhelin, sposti, palautus) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"))
                {
                    $stmt->bind_param("sssssissss", $Tyyppi, $Malli, $Sarjanumero, $Paikka, $Kuvaus, $Lainassa, $Lainaaja, $Puhelin, $Sposti, $Palautus);
                    $stmt->execute();
                    $stmt->close();
                }
                else
                {
                    echo "ERROR: Could not prepare SQL statement.";
                }           
}else{
if ($stmt = $mysqli->prepare("INSERT laitteet (tyyppi, malli, sarjanumero, paikka, kuvaus, lainassa) VALUES (?, ?, ?, ?, ?, ?)"))
                {
                    $stmt->bind_param("sssssi", $Tyyppi, $Malli, $Sarjanumero, $Paikka, $Kuvaus, $Lainassa);
                    $stmt->execute();
                    $stmt->close();
                }
                else
                {
                    echo "ERROR: Could not prepare SQL statement.";
                }   
}
mysqli_close($mysqli);
?>

最佳答案

更改您的插入查询。您缺少

$mysqli->prepare("INSERT laitteet (tyyppi, malli, sarjanumero, paikka, kuvaus, lainassa) VALUES (?, ?, ?, ?, ?, ?)"))

$mysqli->prepare("INSERT into laitteet (tyyppi, malli, sarjanumero, paikka, kuvaus, lainassa) VALUES (?, ?, ?, ?, ?, ?)"))

关于php - 如何将图像添加到php mysql数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23673627/

相关文章:

php - Blade if() 条件错误

PHP 限制输出中的行或字符

Mysql表存储年龄组范围

java - 在 Java 中导入 CSV 文件

javascript - 删除整个数据库而不是一行

php - 黑钻石问号问题

mysql - 我还需要在本地安装 MySQL 吗?

mysql - Perl 将数据从一个数据库复制到另一个数据库

Android Sqlite 数据库组建

android - 在 Android 中打开 sqlite 数据库连接问题