簡體   English   中英

允許用戶添加帶有多個圖像的產品 t

[英]allow the user to add product t with multiple images

我正在處理應該允許用戶添加他的產品進行銷售的頁面,我確實讓用戶添加了產品信息,但不知道如何允許用戶在添加產品時同時上傳多張圖片信息

這是我的代碼,所以你們可以更好地了解我想要什么:

<form action="annonces/addAnnonce.php"method="post"id="addAnnonceForm">
                            <div class="mb-3">
                            <label class="form-label">Annonce title</label>
                            <input type="text" class="form-control"name="title">
                            </div>
                            <div class="mb-3">
                            <label class="form-label">Category</label>
                            <select class="form-select"name="category" aria-label="Default select example">
                                <option value="">cars</option>
                            </select>
                            </div>
                            
                            <div class="mb-3">
                            <label class="form-label">Phone / Contact info :</label>
                            <input type="text" class="form-control"name="phone">
                            </div>

                            <div class="mb-3">
                            <label class="form-label">location:</label>
                            <select class="form-select"name="location" aria-label="Default select example">
                                <option value="1">Khartoum</option>
                            </select>
                            </div>

                            <div class="mb-3">
                            <label class="form-label">Annonce images:</label>
                            <input type="file" class="form-control"name="images[]" multiple>
                            </div>
                            <button type="submit" class="btn btn-primary mt-2 mb-3">Add Annonce</button>

這是 AddAnnonce.php:

function add_new_annonce($title , $category , $location , $uid ) {

    global $conn;

    if (!empty($title) && !empty($location) && !empty($uid)) {
        $n_title = mysqli_real_escape_string( $conn , strip_tags($title)); 
        $n_location = mysqli_real_escape_string( $conn , strip_tags($location)); 
        
        $publish_date =  date('d-m-y');
        $n_uid = (int)$uid;

        if ($n_uid == 0)
            return false;


        $query = "INSERT INTO annoncements(title , category ,location , publish_date , uid)
        VALUES('$n_title', '$category' , '$n_location', '$publish_date' , '$n_uid' )";
        
        $qresult = mysqli_query($conn , $query);

        if (!$qresult)
            return false;

        if ($qresult)
            return true;

    }
   }



    if ($_SERVER['REQUEST_METHOD']  == 'POST') {
            $title= $_POST['title'];
            $phone = $_POST['phone']; 
            $location = $_POST['location'];

            if (!empty($_POST['title']) && !empty($_POST['phone']) && !empty($_POST['location'])) {
                $result = add_new_annonce( "$title","$phone" ,"$location" , $_SESSION['user_info']->user_id );

            if ($result) {
                echo "success";
            }
            if (!$result) {
                echo "something is wrong";
            }

        }
    
}

我知道我必須創建另一個表 annoncements_images 等等,但是我找不到如何在該表中插入具有多個圖像和 annonce_id 的多個圖像的方法,我如何獲取 annonce_id 並將其插入到 annoncements_images 中? 這真的讓我很困惑。 請幫忙,如果不清楚,請告訴我,以便我解釋更多。

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

使用 multipart/form-data 上傳多個文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM