你好,我有一个大问题。我有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
}
?>
答案 0 :(得分:0)
我认为当前代码不起作用,因为您有两个名称为manufacture
的html元素。尝试删除输入字段(<input name="manufacture" type="text">
)。
答案 1 :(得分:0)
可能会出现错误,因为下拉菜单中会加上斜线。