1
我新秀在PHP和HTML,我有这个模态具有在它,我需要用于插入图像..为什么<输入=“文件”>模态不能通过图像到PHP
if (isset($_POST['add_roomtype_action'])) {
require 'script/addRoomType.php';
}
<div class="modal fade" id="add_roomtype_modal" tabindex="-1" role="dialog"
aria-labelledby="add_roomtype_modal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-
hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Add Room Type</h4>
</div>
<form action="room_management.php" method="post"
autocomplete="off">
<div class="modal-body">
<input type="hidden" id="upd_roomtype_id" name =
"add_roomtype_idnm">
<label style="font-size: 10pt">Room Type : </label>
<input type="text" id="add_roomtype" name = "add_roomtypenm"
style="font-size: 10pt" ><br></br>
<label style="font-size: 10pt">Rate : </label>
<input type="text" id="addupd_rate" name = "add_ratenm"
style="font-size: 10pt" ><br></br>
<label style="font-size: 10pt">Image : </label>
<input type="file" id ="add_roomtypeImgid"
name="add_roomtypeImgnm" accept="image/x-png,image/jpeg">
</div>
<div class="modal-footer">
<button type="button" class="btn" data-
dismiss="modal">Close</button>
<button type="submit" class="btn" id = "add_roomtype_action"
name = "add_roomtype_action">Add</button>
</div>
</form>
</div>
</div>
</div>
,这是PHP文件,该文件的模式将调用
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "afgroms";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_POST['add_roomtype_action'])){
$roomtypeid = $_POST['add_roomtype_idnm'];
$roomtype = $_POST['add_roomtypenm'];
$rate = $_POST['add_ratenm'];
$file = $_FILES['add_roomtypeImgnm'];
$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
$fileType = $file['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg','jpeg','png');
if(in_array($fileActualExt, $allowed)){
if($fileError === 0)
{
if ($fileSize > 500000) {
mysql_query("UPDATE `tbl_roomtype` SET `RoomType` =
'$roomtype', `Rate` = '$rate', `Image` = '$img' WHERE RoomTypeID =
".$roomtypeid);
echo "<script>";
echo "alert(\"Successfully Added!\");";
echo "</script>";
}else{
echo "<script>";
echo "alert(\"File size too big!\");";
echo "</script>";
}
}else
{
echo "<script>";
echo "alert(\"There was an error\");";
echo "</script>";
}
}else
{
echo "<script>";
echo "alert(\"You cannot upload this type of file\");";
echo "</script>";
}
}
?>
,但这个错误继续发生:注意:未定义指数:add_roomtypeImgnm ... 帮我在这里的家伙,我不知道什么问题。我已经试图改变我的名字和身份证,同样的错误不断发生。
尝试使用多部分表单数据... – steven
那是什么先生? –
https://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean – steven