如何将图像添加到php mysql数据库? [英] How to add an image to php mysql database?
问题描述
我有这个数据库添加页面,它允许你向数据库添加更多的对象,它工作正常,但我需要条目附加图像,不能让它工作。下面是我当前的工作解决方案( - 图像),我需要添加什么才能将图像上传到条目。变量是芬兰语,因为这是我需要最终产品所需的语言,所以不要介意它们。
I have this database add page, which allows you to add more objects to a database and it works fine, but I need the entries to have an image attached to them and cant get it to work. Below is my current working solution (- the image), what do I need to add to make it able to have images uploaded to the entries. The variables are in finnish because that is the language I need to have the final product in so never mind them.
以下是布局的图片
添加页面: http://imgur.com/7y9mjoc
显示数据库中所有内容的索引页面: http://imgur.com / jwYbZZT
The index page that shows everything in the database: 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);
?>
推荐答案
您的查询Syntex不正确 - 您错过了' INTO'
替换你的if语句如下
当前 -
if($ stmt = $ mysqli-> prepare(INSERT laitteet) (tyyppi,malli,sarjanumero,paikka,kuvaus,lainassa)VALUES(?,?,?,?,?,?)));
Your query Syntex is not correct-you are missing 'INTO'
replace your if statement as follows
current-
if ($stmt = $mysqli->prepare("INSERT laitteet (tyyppi, malli, sarjanumero, paikka, kuvaus, lainassa) VALUES (?, ?, ?, ?, ?, ?)"));
**After correction**-
`if ($stmt = $mysqli->prepare("INSERT INTO laitteet (tyyppi, malli, sarjanumero, paikka, kuvaus, lainassa) VALUES (?, ?, ?, ?, ?, ?)"));`
这篇关于如何将图像添加到php mysql数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!