2013-10-31 64 views
0

我創建了一個下拉列表,其中我從一個表'category'(它有兩列cat_id和類別名稱)中提取數據,我想要插入列值另一個表畫廊..我很能獲取CAT_ID但無法獲取類別名稱..please help..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>'; 
     } 


    ?> 
+0

不知道我理解這個問題。在創建下拉菜單時,您是否遇到了獲取類別名稱的問題,或者在用戶上傳圖像時插入了類別ID? – Barmar

+0

http://stackoverflow.com/questions/16514594/in-php-and-jquery-make-one-drop-down-depend-on-another-drop-down-list – user2615302

+0

@Barmar是它與提取類別名 – user2819264

回答

0

希望這可以幫助你,

 <?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"; 
       } 
      } 
      ?> 
+0

謝謝你buddy @chinnu R – user2819264

相關問題