java上传图片到mysql数据库中_将图像上传到mysql数据库

问题是您在设置图像名称后绑定查询上的参数,尝试这样:

$server = "localhost";

$username = "root";

$password = "root3";

$dbname = "sampledb";

// creat connection

$connection = new mysqli($server, $username, $password, $dbname);

// check the connection

if ($connection->connect_error)

{

die("connect to database failed :" . $connection->connect_error);

}

// check value from select menu

if ($_POST['typelist'] == 'item')

{

// prepare and bind parameters

if (isset($_FILES['item_image']))

{

// set all parameters FIRST TO BIND ON THE QUERY

$image = $_FILES['item_image']['name']; // Now you have the image name

$temp = $_FILES['item_image']['tmp_name'];

$path = "../images/items/$image";

move_uploaded_file($temp, $path);

$manufacturing_year = $_POST['manufacturing_year'];

$length = $_POST['item_length'];

$width = $_POST['item_width'];

$weight = $_POST['item_weight'];

$price = $_POST['item_price'];

$description = $_POST['item_description'];

$model = $_POST['item_model'];

$itemquery = $connection->prepare("insert into items(item_image, item_manufacturing_year, item_Length, item_width, item_weight, item_price, item_description, item_model) VALUES (? , ? , ? , ? , ? , ? , ? , ?)");

$itemquery->bind_param("bsssssss", $image, $manufacturing_year, $length, $width, $weight, $price, $description, $model);

$itemquery->execute();

$itemquery->close();

$connection->close();

}

}

尝试使用var_dump()php函数来查看图像名称值是否正确 . 正如您所做的那样,图像名称可能设置为null .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值