0

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

 <?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>';
        }


   ?>
BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • Not sure I understand the question. Is your problem with fetching the category name when you create the drop-down, or with inserting the category ID when the user uploads an image? – Barmar Oct 31 '13 at 19:31
  • http://stackoverflow.com/questions/16514594/in-php-and-jquery-make-one-drop-down-depend-on-another-drop-down-list – user2615302 Oct 31 '13 at 19:37
  • @Barmar yes it is with fetching categoryname – user2819264 Nov 01 '13 at 07:54
  • So what does the title of the question have to do with the actual problem? – Barmar Nov 01 '13 at 15:05

1 Answers1

0

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";
                }
            }
          ?>
Krish R
  • 22,583
  • 7
  • 50
  • 59