我觉得我的问题很简单,但第一次真的使用mysqli并插入数据库。
我目前正在通过表单添加图片,但我希望图片路径也添加到我的数据库中,
一切正常,除非它没有向我的数据库添加任何内容,
也没有错误。
我认为这是触发查询插入的问题,无论哪种,我都可以使用帮助。
这是我的数据库: http://imgur.com/KhhH5H4
imageinsert.php
<?php
include("db_connect.php");
include("index.php");
?>
<?php
if(isset($_POST['submit']) && empty($_FILES['file']['name'])){
header("Location:index.php");
}
if(isset($_FILES['file']['name'])){
$name = $_FILES['file']['name'];
$size = $_FILES['file']['size'];
// set max size of 2mb in bytes
$maxsize = 2097152;
$pre_extension = explode('.', $_FILES['file']['name']);
$type = $_FILES['file']['type'];
$tmp_name = $_FILES['file']['tmp_name'];
$ext = end($pre_extension);
if(!empty($name)){
if( $ext == "png"
|| $ext == "PNG"
|| $ext == "jpg"
|| $ext == "JPG"
|| $ext == "JPEG"
|| $ext == "jpeg"
|| $ext == "gif"
|| $ext == "GIF"
)
if ($_FILES['file']['error'] == 0){
if( !file_exists('../uploads/')){
$location = '../uploads/';
mkdir($location,077,1);
}
$location = '../uploads/';
move_uploaded_file($tmp_name, $location.$name);
/// here is where I tried to add the files into my database ///////////////
////////////////////////////////////////////////////////////////////
$currentTime = date("Y-m-d H:i:s");
$sql = mysqli_query($link, "INSERT INTO images (id, img_path,img_date) VALUES ((int), $location, $currentTime )");
if(!mysqli_query($link, $sql)) {
echo ("error: ".mysqli_error($link));
}
else {
echo " added deep into the db";
}
mysqli_close($link);
}
else {
echo " errored out"; }
}
else {
exit();
}
}
else{
}
?>