gpt4 book ai didi

php - 在HTML FORM + IMAGE UPLOAD + PHP + MYSQL中选择

转载 作者:行者123 更新时间:2023-11-29 16:11:57 24 4
gpt4 key购买 nike

你好,我有一个大问题。我有 php 代码和一个带有图像上传输入的 html 表单,还有一些文本输入位置并且工作正常,但我想在我的表单中添加下拉选择。但是,当我将 select 元素放入代码中后,它不再将照片上传到服务器,也不再将 mysql 数据粘贴到我的数据库中。我希望你能帮助我。

<?php    
if(isset($_POST['upload_img'])){

$file_name = $_FILES['image']['name'];
$file_type = $_FILES['image']['type'];
$file_size = $_FILES['image']['size'];
$file_tmp_name = $_FILES['image']['tmp_name'];

if($file_name){
move_uploaded_file($file_tmp_name,"images/$file_name");
}
}
?>
<?php
include 'includes/upload.php';

if (isset($_POST['upload_img']) && $_POST['upload_img']=="submit")
{
$image = $file_name;
$car_number = addslashes($_POST['car_number']);
$manufacture = addslashes($_POST['manufacture']);
$model = addslashes($_POST['model']);
$year = addslashes($_POST['year']);
$transmission = addslashes($_POST['transmission']);
$type = addslashes($_POST['type']);
$currency = addslashes($_POST['currency']);
$km_mileage = addslashes($_POST['km_mileage']);
$fuel_type = addslashes($_POST['fuel_type']);

$sql = "INSERT INTO my_garage (image,car_number,manufacture,model,year,transmission,type,currency,km_mileage,fuel_type) VALUES ('$image', '$car_number','$manufacture','$model','$year','$transmission','$type','$currency','$km_mileage','$fuel_type')";
if($result = mysql_query($sql) or die (mysql_error()))
{
echo "uspeshno.<br>";
}
}else{
?>

<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">

<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/styles.css">



<form action="" method="post" enctype="multipart/form-data">

<label>upload image</label><br>
<input type="file" name="image"><br>
<br><br>

car_number:
<input name="car_number" type="text"><br><br>


<select class="browser-default" name="manufacture">
<option value="">Select Manufacturer</option>
<option value="Mercedes-Benz">Mercedes-Benz</option>
<option value="Hyundai">Hyundai</option>
<option value="Toyota">Toyota</option>
</select>

manufacture:
<input name="manufacture" type="text"><br><br>
model:
<input name="model" type="text"><br><br>
year:
<input name="year" type="text"><br><br>
transmission:
<input name="transmission" type="text"><br><br>
type:
<input name="type" type="text"><br><br>
currency:
<input name="currency" type="text"><br><br>
km_mileage:
<input name="km_mileage" type="text"><br><br>
fuel_type:
<input name="fuel_type" type="text"><br><br>

<input name="upload_img" class="btn" type="submit" value="submit">
</form>

<?php
}
?>

最佳答案

我认为当前的代码不起作用,因为你有两个名为 manufacture 的 html 元素。尝试删除输入字段( <input name="manufacture" type="text"> )。

关于php - 在HTML FORM + IMAGE UPLOAD + PHP + MYSQL中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55181939/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com