Php 如何在输入类型文件中发送动态值?

Php 如何在输入类型文件中发送动态值?,php,file,post,input-type-file,Php,File,Post,Input Type File,我已经创建了一个编辑表单,我正在编辑我的房间号、房间描述和房间图像等。基于类别id 第一个编辑表单将从数据库中获取数据。 示例代码: if (isset($_GET['id'])) { $current_id = $_GET['id']; $query=mysql_query("select * from room where room_id='$current_id'");

我已经创建了一个编辑表单,我正在编辑我的房间号、房间描述和房间图像等。基于类别id

第一个编辑表单将从数据库中获取数据。 示例代码:

if (isset($_GET['id'])) 
                { 
                    $current_id = $_GET['id'];
                    $query=mysql_query("select * from room where room_id='$current_id'");
                        $i = 0; 
                        while($row=mysql_fetch_array($query))
                        {
                            $i++; 
                            $room_id=$row['room_id'];
                            $cat_id=$row['cat_id'];
                            $room_number=$row['room_no'];
                            $room_desc=$row['room_desc'];
                            $room_image=$row['room_image'];

                    ?>
                    <table class="table table-bordered table-hover table-striped">
                            <thead>
                                <tr>
                                    <th>Room Id</th>
                                    <th>Category Type</th>
                                    <th>Room Number</th>
                                    <th>Room Description</th>
                                    <th>Room Image</th>

                                </tr>
                            </thead>
                            <tbody>
                             <tr class="active">
                                    <td><input type="text" value="<?php echo $room_id; ?>" readonly="readonly" name="room_id"></td>
                                    <td>

                                    <?php           
                                                // Slecting cat_id for displaying cat_type on Edit form
                                    $query_room=mysql_query("SELECT * FROM `category` WHERE cat_id in (". $cat_id .")");

                                    while($row=mysql_fetch_array($query_room))
                                    {
                                        $category_name=$row['cat_type'];
                                        $category_id=$row['cat_id'];
                                        echo '<input type="text" value='.$category_name.' readonly="readonly" name="cat_name">';

                                        echo '<input type="hidden" value='.$category_id.' readonly="readonly" name="cat_id">';  // hidden value for cat_id to fetch data from category
                                         $_SESSION['imagesession'] = "data:image/png;base64, base64_encode($room_image)";
                                    }
                                    ?>
                                    </td>
                                    <td><input type="text" value="<?php echo $room_number ;?>" name="room_number" required></td>
                                    <td><input type="text" value="<?php echo $room_desc ;?>" name="room_desc" required></td>
                                    <td><input type="image" src="data:image/png;base64,<?php echo base64_encode($room_image);?>" name="myimage" alt="No Photo" title="Click to View in Detail" height="50px" width="50px"/>

                                    <label>Upload Image</label>
                                        <input type="file" id="uploadImage" value="<?php echo base64_encode($room_image);?>" name="image" onChange="PreviewImage();" />
                                        <img id="uploadPreview" style="width: 200px; height: 300px; border-style:none" />

                                    </td>
                                    </tr>
                                </tbody>
         </table>
                         </div>
                        </div>
                        <button type="submit" class="btn btn-success" name="update_rooms">Update Rooms</button>
                        <button type="reset" class="btn btn-danger">Reset</button>
                         </form>
if(isset($\u GET['id']))
{ 
$current\u id=$\u GET['id'];
$query=mysql\u query(“从文件室中选择*,其中文件室\u id='$current\u id'”);
$i=0;
while($row=mysql\u fetch\u array($query))
{
$i++;
$room_id=$row['room_id'];
$cat_id=$row['cat_id'];
$room_number=$row['room_no'];
$room_desc=$row['room_desc'];
$room_image=$row['room_image'];
?>
房号
类别类型
房间号
房间描述
房间图像
你也可以用这个

从数据库中获取此
$existing\u category\u图像
,无需从表单中发布

if($imageData == '' || $imageData == null){
$sql = "UPDATE room SET cat_id='$cat_id', room_no='$room_number', room_desc='$room_desc' WHERE room_id='$current_id'";
}else{
$sql = "UPDATE room SET cat_id='$cat_id', room_no='$room_number', room_desc='$room_desc', room_image='$imageData' WHERE room_id='$current_id'";
}

写下:

    if($imageData == '' || $imageData == null){ 
            $imageData = $existing_category_image;
     }
以前

$sql = "UPDATE room SET cat_id='$cat_id', room_no='$room_number', room_desc='$room_desc', room_image='$imageData' WHERE room_id='$current_id'";

$existing_category_image是否保存该行当前数据库中的图像?如果是,请设置$imageData=$existing_category_image并像往常一样保存。我无法将$existing_category_image值传递到数据库。是,但我无法将$existing_category_图像值从表单传递到php以及数据库谢谢您的帮助lp.它在两种情况下工作:1.“如果用户添加了一个新图像”,2.“如果用户编辑了现有图像”,但如果图像已经在数据库中,并且用户没有更改任何内容,我的意思是,他不想编辑图像,那么他将提交编辑室,然后我收到一个错误,错误是“”:file_get_contents():Filename不能为空”
$sql = "UPDATE room SET cat_id='$cat_id', room_no='$room_number', room_desc='$room_desc', room_image='$imageData' WHERE room_id='$current_id'";