简体   繁体   English

从下拉列表中获取列值并将其插入到另一个表中

[英]fetch column values from drop down and insert it in another table

i have created a dropdown in which i am fetching data from one table 'category'(it has two column cat_id and category name) and i want to insert column value in another table GALLERY ..i am able to fetch cat_id but can't fetch categoryname ..please help..SQL injection not a problem 我创建了一个下拉列表,其中我要从一个表“ category”(具有两列cat_id和类别名称)中获取数据,并且我想在另一张表GALLERY中插入列值。我可以获取cat_id,但不能获取类别名称..请帮助..SQL注入不是问题

 <?php
    include_once("header.php");
    include ("connection.php");
    if(isset($_REQUEST['ansave']))
    {
    $a=$_REQUEST['choosecategory'];
    $image=$_FILES['uploadgallery']['name'];// name given in input type 
    $ext=substr(strchr($image,'.'),1);//it breaks the string in part so that format can be matched
    if($ext!='jpg' && $ext!='jpeg' && $ext!='png' && $ext!='gif' && $ext!='JPG' && $ext!='JPEG')
    {
    echo "please select image";
    }
    else
    {
    $path="gallery/".$image; //folder in which image to be saved
    $action=copy($_FILES['uploadgallery']['tmp_name'],$path);//name given in input type (line72)
    $query="insert into gallery (`cat_id`,`galimage`) values('$a','$image')";
    $result=mysql_query($query);`enter code here`
    echo "insert successfully";
    }
    }
    ?>


         <option selected> -- select -- </option>';
           <?php $sql = "SELECT * FROM category";
        $result = mysql_query($sql);
        while($row=mysql_fetch_array($result)){
        echo '<option value="'.$row['cat_id'].'">'.$row['categoryname'].'</option>';
        }


   ?>

Hope it may helps you, 希望对您有帮助,

      <?php
             include_once("header.php");
             include ("connection.php");
             if(isset($_REQUEST['ansave']))
             {
                $a=$_REQUEST['choosecategory'];
                $image=$_FILES['uploadgallery']['name'];// name given in input type
                $ext=substr(strchr($image,'.'),1);//it breaks the string in part so that format can be matched
                if($ext!='jpg' && $ext!='jpeg' && $ext!='png' && $ext!='gif' && $ext!='JPG' && $ext!='JPEG')
                {
                     echo "please select image";
                 }else  {
                     $path="gallery/".$image; //folder in which image to be saved
                     $action=copy($_FILES['uploadgallery']['tmp_name'],$path);//name given in input type (line72)

                     $sqlCategory = "SELECT categoryname FROM category where cat_id='".$a."' ";
                     $resultCategory = mysql_query($sqlCategory);
                     $rowCategory=mysql_fetch_array($resultCategory);
                     $categoryname = $rowCategory['categoryname']; // category name

                     $query="insert into gallery (`cat_id`,`galimage`) values('$a','$image')";
                     $result=mysql_query($query);
                    echo "insert successfully";
                }
            }
          ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将从MySql填充的下拉列表中选择的整个行值插入另一个MySql表 - Insert entire row values selected from MySql populated drop down list into another MySql Table 将各种下拉列表中的值插入数据库表 - insert values from various drop down list to database table 从下拉列表的选定值创建表列标题 - Create table column headers from selected values of a drop down list 将选定的下拉值显示到另一个表 - show the selected drop down values to the another table 如何从另一个表的下拉列表中插入所选名称的ID? - How to insert ID of a selected name from drop down list in another table? 如何从下拉列表中捕获主键并插入为另一个表的外键? - How to capture primary key from drop down and insert as foreign key of another table? 尝试将下拉列表中的数据作为外键插入另一个表中。 数据未插入 - Trying to insert data from a drop-down list as a foreign key in another table. Data not inserted 从其他表格中获取并添加下拉菜单 - Fetch and add drop down menu from different table 如何从下拉列表中选择值,如何从另一个表中获取相应的值,然后将其放入另一个下拉列表中? - How to select value from a drop-down list, get the corresponding values from another table, then put those into another drop-down list? 从下拉列表插入值但不插入时没有错误 - No error when inserting values from drop down but won't insert
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM