dongtan7998 2015-01-06 08:57
浏览 44
已采纳

无法将两个数组值插入数据库

Here is the code I am using for multiple image upload for every entry in the database; id, image, name, date. By using this code, the image name is inserting correctly but I have a problem with the name field. I want to insert the name using $product_name= $_POST['pro_name']; but it only inserts 'array' in name field.

<?php
include('../config.php');
if (isset($_POST['submit'])) {
    $product_name = $_POST['pro_name'];

    $j = 0;     // Variable for indexing uploaded image.
    $target_path = "uploads/";     // Declaring Path for uploaded images.
    for ($i = 0; $i < count($_FILES['file']['name']) && $product_name < count($product_name); $i++) {
        // Loop to get individual element from the array
        $validextensions = array("jpeg", "jpg", "png");      // Extensions which are allowed.
        $ext = explode('.', basename($_FILES['file']['name'][$i]));   // Explode file name from dot(.)
        $file_extension = end($ext); // Store extensions in the variable.
        $target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext) - 1];     // Set the target path with a new name of image.
        $j = $j + 1;      // Increment the number of uploaded images according to the files in array.
        if (($_FILES["file"]["size"][$i] < 100000000)     // Approx. 100kb files can be uploaded.
                && in_array($file_extension, $validextensions)) {

            if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {

                $finel_name = explode('/', $target_path);
                $image_name_final = $finel_name[1];
                $jajsj = "insert into spec_product set image='$image_name_final', name='$product_name'";
                $janson = mysql_query($jajsj) or die(mysql_error());
                // If file moved to uploads folder.
                echo $j . ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
            } else {     //  If File Was Not Moved.
                echo $j . ').<span id="error">please try again!.</span><br/><br/>';
            }
        } else {     //   If File Size And File Type Was Incorrect.
            echo $j . ').<span id="error">***Invalid file Size or Type***</span><br/><br/>';
        }
    }
}
?>
  • 写回答

2条回答 默认 最新

  • dpglo66848 2015-01-06 09:35
    关注

    replace in your code

    for ($i = 0; $i < count($_FILES['file']['name']); $i++)
        {
    

    and add this before your query execute

    $product_name_final= $product_name[$i];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ghpython这里总是报错而且rhino视图窗口内不显示怎么办
  • ¥15 布尔运算推导,请证明
  • ¥15 有没有人会打学生成绩管理系统呀
  • ¥15 在使用Fiddler和夜神模拟器抓包的时候一直出现443该怎么办啊QAQ搜了好几个笔记都没有解决
  • ¥15 3x7的二维数组A、B、C,A中的任意1个数组元素与B的任意1个数组元素、同时又与C的任意1个数组元素比较,把不同位置出现相同数的比较称为无意义,反之称为有意义,把有意义的比较打印输出。
  • ¥20 预测模型怎么处理原始数据(随机森林)
  • ¥20 请问discuz3.5如何实现插入ckplayer全能播放器功能呢?
  • ¥15 thingsboard代码编译出错误
  • ¥15 博途v18仿真报错怎么解决
  • ¥15 欧姆龙plc枕式包装机 ST编程