簡體   English   中英

從下拉列表中獲取列值並將其插入到另一個表中

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

我創建了一個下拉列表,其中我要從一個表“ 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>';
        }


   ?>

希望對您有幫助,

      <?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.

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