它总是回声"保存图像路径"但没有得到任何保存
我还测试了连接并正常连接
我已经搜索过了,我得到的唯一结果就是使用" mysql_connect"很快就会被删除
//我在这段代码中没有错误
//submiting form
if(isset($_POST['submit']))
{
//connecting ot db
$con = mysqli_connect('localhost', '', '', '');
//naming and saving into a folder
$filetmp = $_FILES["file_img"]["tmp_name"];
$filename = $_FILES["file_img"]["name"];
$filetype = $_FILES["file_img"]["type"];
$filepath = "article_images/".$filename;
// insert path into db -but nothing gets done
move_uploaded_file($filetmp,$filepath);
$query = "INSERT INTO 'Article' ('img_name','img_path','img_type') VALUES ('$filename','$filepath','$filetype')";
if($query)
{
echo "image path saved";
} else {
echo "nothing saved";
}enter code here
}
?> enter code here
表单工作正常,但无法查看错误
答案 0 :(得分:1)
执行插入查询
所以,你的代码将是这样的:
$query = mysqli_query($con, "INSERT INTO 'Article' ('img_name','img_path','img_type') VALUES ('$filename','$filepath','$filetype')");
注意:将Hash Image名称插入数据库之前。
答案 1 :(得分:0)
Use code like this.
<?php
$DBhost = "localhost";
$DBuser = "";
$DBpass = "";
$DBname = "";
$DBcon = new MySQLi($DBhost,$DBuser,$DBpass,$DBname);
if(isset($_POST['submit']))
{
//naming and saving into a folder
$filetmp = $_FILES["file_img"]["tmp_name"];
$filename = $_FILES["file_img"]["name"];
$filename = time()."_".$filename;
$filetype = $_FILES["file_img"]["type"];
$filepath = "article_images/".$filename;
// insert path into db -but nothing gets done
move_uploaded_file($filetmp,$filepath);
$query = $DBcon->query("INSERT INTO 'Article' ('img_name','img_path','img_type') VALUES ('$filename','$filepath','$filetype')");
if($query)
{
echo "image path saved";
} else {
echo "nothing saved";
}enter code here
}
?>
答案 2 :(得分:0)
您是否在表单中使用 enctype ?如果不是,您需要在表单标记中使用它,然后重试..
<form action="filename.php" method="post" enctype="multipart/form-data">
希望它有所帮助...