0
你好,我嘗試上傳表單信息到數據庫和每一個領域上傳除了圖像文件和圖像移動到路徑,但當我檢查表時圖像列中沒有圖像名稱...我的代碼:上傳圖像到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'])) {
$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);
// set all parameters and execute the query
$image = $_FILES['item_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->execute();
$itemquery->close();
$connection->close();
}
}
爲什麼使用'b'並在'bind_param'中傳遞字符串? –
嘗試在定義'$ model'之後在行上放置'$ itemquery-> bind_param'。 – castis
@RC你認爲是錯的。 –