PHP MySQL插入不';我不能工作,我可以';我没有发现任何错误
我有这个PHP代码,我正试图将数据插入我的数据库。它似乎不起作用,我也不知道为什么。我试图回显mysqli_错误,但没有显示任何错误。我也响应了这个查询,当我直接在phpmyadmin中运行它时,它工作得很好 表格PHP MySQL插入不';我不能工作,我可以';我没有发现任何错误,php,mysql,mysqli,Php,Mysql,Mysqli,我有这个PHP代码,我正试图将数据插入我的数据库。它似乎不起作用,我也不知道为什么。我试图回显mysqli_错误,但没有显示任何错误。我也响应了这个查询,当我直接在phpmyadmin中运行它时,它工作得很好 表格 <form method="POST" action="images.php?#werk" enctype="multipart/form-data"> <h6>Voeg nieuwe afbeelding toe<
<form method="POST" action="images.php?#werk" enctype="multipart/form-data">
<h6>Voeg nieuwe afbeelding toe</h6>
<div class="file-field input-field">
<div class="btn">
<span>Bestand</span>
<input name="install" type="file">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
<div class="input-field">
<textarea id="textarea1" name="caption" class="materialize-textarea"></textarea>
<label for="textarea1">Beschrijving</label>
</div>
<div class="row">
<button class="btn waves-effect waves-light" type="submit" name="submit2">Voeg toe
<i class="material-icons right">add</i>
</button>
</div>
</form>
connect.php
$conn = mysqli_connect($server, $usernameDB, $password, $usernameDB);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
附加安装
function addInstallation($caption, $name){
$target_dir = "../in-progress.johnkok.com/img/installations/";
if($_FILES[$name]["size"] > 0){
$target_file = $target_dir . basename($_FILES[$name]["name"]);
$uploadOK = 1;
$image_type = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
$check = getimagesize($_FILES[$name]["tmp_name"]);
if($check !== false){
$uploadOK = 1;
}
else{
$feedback2 = "Bestand is geen afbeelding.";
$uploadOK = 0;
}
if($uploadOK !== 0){
move_uploaded_file($_FILES[$name]["tmp_name"], $target_file);
$target_file = "img/installations/" . basename($_FILES[$name]["name"]);
$query = mysqli_query($conn, "INSERT INTO `Installations`(`caption`, `image_path`) VALUES ('$caption','$target_file')");
}
}
mysqli_close($conn);
}在php文件中,将$conn变量添加到传递的内容中
include "includes/connect.php";
if(isset($_POST['submit2'])){
addInstallation($_POST['caption'], "install",$conn);
}
在附加安装文件中包括连接文件。 例如:
include "includes/connect.php";
function addInstallation($caption, $name){
// some code
}
您确定您的脚本通过了条件“if($uploadOK!==0)”吗?出现了什么错误?move\u uploaded\u文件似乎工作正常您没有向函数公开
$conn
变量。您对mysqli_查询的调用可能失败,但您从未检查错误。您调试过查询吗?我的意思是不使用mysqli_query()的echo$query。并将该查询回传到数据库。
include "includes/connect.php";
function addInstallation($caption, $name){
// some code
}