SitePoint Sponsor

User Tag List

Page 7 of 31 FirstFirst ... 3456789101117 ... LastLast
Results 151 to 175 of 767
  1. #151
    SitePoint Enthusiast mayank's Avatar
    Join Date
    Jul 2003
    Location
    India
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi everybody,

    i have been receiving many mails on further enhancing the gallery script ... i apologize for not replying to all in time ... i am gonna try and give answers to those mails here ...

    Quote Originally Posted by Murray Barnes
    Let me first say that your tutorial on SitePoint is excellent. I am hoping that
    you can help me though.

    I am having problems getting the image management working. The main areas are:

    - Editing Photo Details and Moving a Photo to a New Category

    - Deleting a Photo

    I know that there are several people working on this and it would be great if
    you could post some working code on the forum.

    Your further help would be greatly appreciated.

    I think i have given a full admin code before in this thread, that deals with all admin functions incorporated in it.
    http://www.sitepointforums.com/showp...1&postcount=48

    For the ones mentioned by Murray, here is a makeshift code which will help you in that.

    PHP Code:
    <?php
        
    include("config.inc.php");

        if( empty(
    $_POST['action']) )
        {
        
    // Firstly Lets get the Photo ID
    ?>

    <form name="edit_photo" action="admin2.php" method="post">

    <b>Enter Photo ID:</b> <input type="text" name="photoid" />
    <input type="submit" value="find" name="action" />

    </form>

    <?php
        
    }
        else if( 
    strcasecmp($_POST['action'], "find")==)
        {
        
    $result mysql_query"SELECT photo_caption,photo_filename,photo_category FROM gallery_photos WHERE photo_id='".addslashes($_POST['photoid'])."'" );
        
    $nr mysql_num_rows$result );
        
        if( 
    $nr )
        {
            echo(
    "Photo not found in DB!");
            exit;
        }    

        
    $row mysql_fetch_array$result );
        
    mysql_free_result$result );

        echo(
    "<a href='viewgallery.php?cid=".$row['photo_category']."&pid=".$_POST['photoid']."'><img src='".$images_dir."/tb_".$row[1]."' border='0' alt='".$row[0]."' /></a>");

        
    // Firstly Lets build the Category List

        
    $result mysql_query"SELECT category_id,category_name FROM gallery_category" );
        while( 
    $row2 mysql_fetch_array$result ) )
        {

            if( 
    $row2["category_id"] == $row["photo_category"] )
            {
    $category_list .=<<<__HTML_END
        <option value="$row2[0]" selected>$row2[1]</option>\n
    __HTML_END;
            }
            else
            {
    $category_list .=<<<__HTML_END
        <option value="$row2[0]">$row2[1]</option>\n
    __HTML_END;
            }
        }
        
    mysql_free_result$result );    
        
    $category_list '<select name="categoryid">'.$category_list.'</select>';
    ?>

    <form name="photo_move" action="admin2.php" method="post">

    <b>Move Photo:</b><br />
    Select New Category: <?php echo($category_list); ?><br />
    Caption: <input type="text" name="caption" value="<?php echo($row["photo_caption"]); ?>" /><br />
    <input type="hidden" value="<?php echo($_POST['photoid']); ?>" name="photoid" />
    <input type="submit" value="save" name="action" />

    </form>

    <br /><br />

    <form name="photo_delete" action="admin2.php" method="post">
    <b>Delete Photo?</b><br />
    <input type="hidden" value="<?php echo($_POST['photoid']); ?>" name="photoid" />
    <input type="submit" value="delete" name="action" onclick="return confirm('Are you sure you want to do delete this photo?')" />

    </form>

    <?php
        
    }
        else
        {
            if( 
    strcasecmp($_POST['action'], "save")==&& !empty( $_POST['categoryid'] ) )
            {
                
    edit_photo($_POST['photoid'], $_POST['caption'], $_POST['categoryid']);
            }
            else if( 
    strcasecmp($_POST['action'], "delete")==&& !empty( $_POST['photoid'] ) )
            {
                
    delete_photo($_POST['photoid']);
            }
            else
            {
                echo(
    "Action not understood"); exit;
            }

            echo(
    "Process completed!");
        }

    // the functions here

    function edit_photo$photo_id$new_caption$new_category 

     
    mysql_query"UPDATE gallery_photos SET photo_caption='".addslashes$new_caption )."', photo_category='".addslashes$new_category )."' WHERE photo_id='".addslashes$photo_id )."'"  ); 
    }

    function 
    delete_photo($photo_id

    global 
    $images_dir;
     
    $result mysql_query(
       SELECT photo_filename 
       FROM gallery_photos 
       WHERE photo_id = '" 
    addslashes($photo_id) . "' 
     "
    );   
     list(
    $filename) = mysql_fetch_array($result); 
     
    mysql_free_result($result); 

     
    unlink($images_dir '/' $filename); 

     
    mysql_query(
       DELETE FROM gallery_photos 
       WHERE photo_id='" 
    addslashes($photo_id) . "' 
     "
    ); 
    }

    ?>
    its possible ...

    < S-Point Articles :: Albinator :: mgZhome :: Beyond illusions />

  2. #152
    SitePoint Enthusiast mayank's Avatar
    Join Date
    Jul 2003
    Location
    India
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Chun
    How can I make the photo upload field optional? I do have a reason for this.
    As it is it seems that the upload will not work without an image. I have
    other fields being uploaded, but would like the photo to be optional
    Well its a photo gallery script ... so basically if you don't give a photo, what would it upload?
    its possible ...

    < S-Point Articles :: Albinator :: mgZhome :: Beyond illusions />

  3. #153
    SitePoint Enthusiast mayank's Avatar
    Join Date
    Jul 2003
    Location
    India
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Edwin
    Can you sujest me how to make pagging in thumbnail mode , example
    limit small picture jus 6 image, so when visitor want the next
    image.

    there be a LINKS to click.

    regards
    edwin

    Well i will suggest you to use a system presented by Kevin Yank in one of this articles in 2002 on SitePoint, here's a link to it:

    http://www.sitepoint.com/article/662/5

    This I would say is most easiest way to implement in your current script without to much of editing.
    its possible ...

    < S-Point Articles :: Albinator :: mgZhome :: Beyond illusions />

  4. #154
    SitePoint Enthusiast mayank's Avatar
    Join Date
    Jul 2003
    Location
    India
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by LeeB
    Hi,

    This tutorial is great, easy to follow and i got it working first time. I am a newB to PHP and itís nice to find something that is both well explained and that acutely worked without having to spend hours debugging.

    Q. How can I get the photo_caption to display with the Thumbnail Listing?

    Hope you can help!
    well edit your viewgallery.php and find this:

    PHP Code:
                    $result_array[] = "<a href='viewgallery.php?cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' /></a>"
    and change it to:

    PHP Code:
                    $result_array[] = "<a href='viewgallery.php?cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' /><br />".$row[1]."</a>"
    its possible ...

    < S-Point Articles :: Albinator :: mgZhome :: Beyond illusions />

  5. #155
    SitePoint Member
    Join Date
    Nov 2003
    Location
    washington
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm using mayank's tutorial to set up something other than a photo album. I created an online product catalog (not and eCommerce shopping cart), to display products for a project I'm starting. Its a very nice tutorial and helped very much in getting me off on the right foot as I'm definetly not an expert at php.

    Since this is a product catalog, I'm having one issue. The editing of products already existing in the DB. I have the Add product form, but I would also like to have the same form prepopulated with the products data (name, price,desc etc..) in order to edit it. I can get the form populated, but thats about as far as I can go. I don't know what I need to do to update the photo along with the other fields if the user decides to add a new one.

    On the same note, how can I modify mayank's upload script to not make the picture a mandatory field? If I try to add a new product without a photo, it doesn't do nothing. Ideally I would like to set it up so that If the user does not upload a photo a predetermined jpg will be used in its place.

    Any help would be appreciated.
    Chun

  6. #156
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Location
    New Jersey
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great article... can't get it to work though..

    When I try I get a fatal error: Call to undefined function: imagecreatefrom()
    on line 32. Here is the code as I have it:

    PHP Code:
    <?
    // This creates a thumbnail of the uploaded image
    $images_dir="./photos/";
    $filename=$_SESSION["photo_filename"];
    echo(
    "Image to be thumbnailed:");
    echo(
    "$images_dir");
    echo(
    "$filename");
     
    // Let's get the Thumbnail size
     
    $size GetImageSize$images_dir."/".$filename );
     if(
    $size[0] > $size[1])
        {
         
    $thumbnail_width 100;
         
    $thumbnail_height = (int)(100 $size[1] / $size[0]);
        }
        else
        {
         
    $thumbnail_width = (int)(100 $size[0] / $size[1]);
         
    $thumbnail_height 100;
        }
       
        
    // Build Thumbnail with GD 1.x.x, you can use the other described methods too
        
    $function_suffix $gd_function_suffix[$filetype];
        
    $function_to_read "ImageCreateFrom".$function_suffix;
        
    $function_to_write "Image".$function_suffix;
        
    // Read the source file
        
    $source_handle $function_to_read $images_dir."/".$filename ); 
        
        if(
    $source_handle)
        {
         
    // Let's create an blank image for the thumbnail
              
    $destination_handle ImageCreate $thumbnail_width$thumbnail_height );
        
         
    // Now we resize it
              
    ImageCopyResized$destination_handle$source_handle0000$thumbnail_width$thumbnail_height$size[0], $size[1] );
        }
        
    // Let's save the thumbnail
        
    $function_to_write$destination_handle$images_dir."/tb_".$filename );
        
    ImageDestroy($destination_handle );
        
    //
        
    $result_final .= "<img src='".$images_dir"/tb_".$filename."' /> File ".($counter+1)." Added<br />";
     
    ?>
    I have the upload form pass values and upload the original file to the photos directory, then calls the convert.php file after the file has been successfully uploaded and saved.

    TIA for your help.

    Aleks
    If you keep doing what you did,
    you will keep getting what you got..

  7. #157
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    Morristown, TN
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mayank
    This I would say is most easiest way to implement in your current script without to much of editing.
    I added navigation links several pages ago in this thread so people don't have to beat their head against the wall.

    Can you tackle the limit of the picture size? I asked for this and so did another person. I am making my gallery for someone who is not that great with computers. the first time he uploaded a picture it was like 1200 x 1100 or something. I need the picture, upon uploading, needs to be resized to about 400 or 450 pixels wide.

  8. #158
    SitePoint Enthusiast drewf's Avatar
    Join Date
    Mar 2002
    Location
    Calgary, AB
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by animal777
    I added navigation links several pages ago in this thread so people don't have to beat their head against the wall.

    Can you tackle the limit of the picture size? I asked for this and so did another person. I am making my gallery for someone who is not that great with computers. the first time he uploaded a picture it was like 1200 x 1100 or something. I need the picture, upon uploading, needs to be resized to about 400 or 450 pixels wide.
    Animal777 my man, good to see you're still around! Glad to see you are still interested in this article and thread like I am. I too am still wondering how to take the freshly uploaded file and resize it to a pre-determined size (say 450px width). I am thinking the upload script has the answers in it partly already. The thumbnail resize part does exactly the resizing part we need. But we need to do this resizing twice. Once to the specified size and once to the thumbnail. I am totally lost on how to do this in script form though.

    I did find an interesting script that does the resizing and sends the image JUST to the browser and does not actually modify the uploaded image itself (non-destructive). I know this is not exactly what we are asking for in our existing scripts from Mayank's article but it may give us or anyone else tackling this issue some insight. It may also be beneficial to others in future. By the way the articles and tutorials on the GD library and PHP on the Internet are horrible. Slowly, very painstakingly slowly I have started to take baby steps into the GD relm. I hope a SitePoint guru can write a detailed article on this type of thing aimed at newbies that actually teaches practicle image resizing to predetermined sizes...

    Anyhow, enough about my rant, here is that code I was talking about. Its pretty cool:

    PHP Code:
    <?PHP
    include("config.inc.php");
    # Constants
    define(MAX_WIDTH450);
    define(MAX_HEIGHT450);
    # Get image location
    $image_file "11.jpg";//str_replace('..', '', $_SERVER['QUERY_STRING']);
    $image_path "$images_dir"/$image_file";
    # Load image
    $img null;
    $ext strtolower(end(explode('.'$image_path)));
    if (
    $ext == 'jpg' || $ext == 'jpeg') {
       
    $img = @imagecreatefromjpeg($image_path);
    } else if (
    $ext == 'png') {
       
    $img = @imagecreatefrompng($image_path);
    # Only if your version of GD includes GIF support
    } else if ($ext == 'gif') {
       
    $img = @imagecreatefrompng($image_path);
    }
    # If an image was successfully loaded, test the image for size
    if ($img) {
       
    # Get image size and scale ratio
       
    $width imagesx($img);
       
    $height imagesy($img);
       
    $scale min(MAX_WIDTH/$widthMAX_HEIGHT/$height);
       
    # If the image is larger than the max shrink it
       
    if ($scale 1) {
           
    $new_width floor($scale*$width);
           
    $new_height floor($scale*$height);
           
    # Create a new temporary image
           
    $tmp_img imagecreatetruecolor($new_width$new_height);
           
    # Copy and resize old image into new image
           
    imagecopyresampled($tmp_img$img0000,
                            
    $new_width$new_height$width$height);
           
    imagedestroy($img);
           
    $img $tmp_img;
       }
    }
    # Create error image if necessary
    if (!$img) {
       
    $img imagecreate(200200);
       
    imagecolorallocate($img255255255); //white image
       
    $black imagecolorallocate($img000);
       
    $red imagecolorallocate($img25500);
       
    imageline($img001990$black); //top border
       
    imageline($img000199$black); //left border
       
    imageline($img1990199199$black); //right border
       
    imageline($img0199199199$black); //bottom border
       
    imageline($img00199199$red); //cross hatch from top left to bottom right
       
    imageline($img19900199$red); //cross hatch from bottom left to top right
       
    $text_color ImageColorAllocate($img000);
       
    ImageString($img36610"Not Found!"$text_color); //text on image
    }
    # Display the image
    header("Content-type: image/png");
    imagepng($img);
    ?>
    I know its not exactly what we are looking for yet but it could be a start. Its also pretty slow because it uses the imagecopyresampled() function to better smooth the image. This function and script for that matter will only work with GD v. 2+, sorry pre-2 people...

    I am still working on all this too. I will see you around and good luck.
    Last edited by drewf; Dec 10, 2003 at 07:32.
    Drew

    "The town where I grew up has a zip code of E-I-E-I-O."

  9. #159
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    every time I delete files from the database I get errors like this

    Warning: unlink(): SAFE MODE Restriction in effect. The script whose uid is 7893 is not allowed to access / owned by uid 0 in /home/radiorally.org.au/htdocs/admin/pic_process_admin.php on line 122

    My files get uploaded as a different user then I dont have the correct access to them.

    what do I have to do to get around this issue?

  10. #160
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    maine
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Edit Order

    I'd like to be able to edit the order of the pics too. Any advice on how to accomplish that?
    I'm thinking to add a column in the gallery_photos table of order_id and then when they display, ORDER them by that... ?

  11. #161
    SitePoint Member benson304's Avatar
    Join Date
    Apr 2003
    Location
    MA
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm having some problems getting the admin.php to work, I tried to add a category and it deleted my other category, and forget about adding in the photo editing functions, they do jack squat.

    If you could help me out a little, that would be cool.
    http://ih0p.com

    My current piece of ish.
    Nothing really there at the moment.

  12. #162
    SitePoint Member
    Join Date
    Oct 2003
    Location
    York, UK
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    imagemagick users?

    is anyone out there using this gallery with imagemagick?

    my gallery is uploading the photos fine, but the thumbnails aren't being generated properly... well, they're not being generated at all...

    is anyone else using imagemagick to render the thumbnails and if so can i please see your upload.php script so i can see where i'm going wrong?

    thanks,

    jonic.

  13. #163
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No im not using image magic but the only problem I have with the script is that when it uploads it sets the owner and group as nobody so when i go to delete an image it wont delete.

    Havent found a way around it yet. any ideas?

    ps try updating imagemagick and what systems etc you using?

  14. #164
    SitePoint Member
    Join Date
    Oct 2003
    Location
    York, UK
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by noddy
    ps try updating imagemagick and what systems etc you using?
    i had a problem with the nobody thing too... i think it's something to do with unix server write permissions or something... when the guy who runs the server i'm on sorted the problem out he said something to that effect... i'll ask him again for you...

    i'm running the very latest versions of mysql, apache, php and imagemagick... i'm just a little annoyed that i can get the script to upload the images, but i can't get imagemagick to generate the thumbnails...

    if you (or anyone) can help out (i'm looking in your direction mayank!) then please let me know!

    jonic.

  15. #165
    SitePoint Enthusiast mayank's Avatar
    Join Date
    Jul 2003
    Location
    India
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well there are 2 things to check ...

    1) ImageMagick path, make sure it leads to the directory where composite is ...
    2) Make sure execu() functions is allowed on your server ...
    its possible ...

    < S-Point Articles :: Albinator :: mgZhome :: Beyond illusions />

  16. #166
    SitePoint Member
    Join Date
    Feb 2004
    Location
    Vancouver
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Links to next / previous image and display and sort by date added

    Is there a way to link to the next / previous image while viewing a single image? I have included the page count and navigation to subsequent pages in the thumbnail view, but would like to carry over similar functionality while viewing individual images...

    Also is there a way to order the thumbs by date and display the date added with the thumbnail?

    Thanks!

  17. #167
    SitePoint Member
    Join Date
    Feb 2004
    Location
    Vancouver
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sub Categories

    Has anyone out there created sub categories or know how to code it?


    Thanks!

  18. #168
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by millrlyt
    Is there a way to link to the next / previous image while viewing a single image? I have included the page count and navigation to subsequent pages in the thumbnail view, but would like to carry over similar functionality while viewing individual images...

    Also is there a way to order the thumbs by date and display the date added with the thumbnail?

    Thanks!
    try putting all the images for a category into an araay then step thru them or do something simular to the next previous page thing

  19. #169
    SitePoint Member
    Join Date
    Feb 2004
    Location
    Vancouver
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try putting all the images for a category into an araay then step thru them or do something simular to the next previous page thing
    I am fairly new at PHP - can you explain further or give me an example of the code?

    Thanks!

  20. #170
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    some place south
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hi

    My first post on this board. im more of a designer than coder so be easy on me

    This is a fantastic gallery set-up. I now a little php, and have just got started on MySQL.

    Ive got the main gallery working ok, with added captions on the thumbnails (thanks mayank)

    My prob is I want to delete images/thumbnails and catagories.

    Im not understanding the last 'added functionality' page of the tutorial. Are they added php pages?

    Ive cut and pasted the code for the admin.php posted by mayank (agian thankyou) but i get this error:


    Parse error: parse error, unexpected T_SL in /usr/local/psa/home/vhosts/saltfordcoins.com/httpdocs/test/admin.php on line 42


    which is ...

    42 $category_list .=<<<__HTML_END
    43 <option value="$row2[0]" selected>$row2[1]</option>\n
    44 __HTML_END;

    What is the admin2.php for and where is the code for it?


    Is there any helpers there that can post up some code to help me, or tell me where im going wrong.

    like i said, im new to php so be easy on me

    Thanks in advance to every one that reads this.

    Ben.

  21. #171
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    Morristown, TN
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by millrlyt
    Is there a way to link to the next / previous image while viewing a single image? I have included the page count and navigation to subsequent pages in the thumbnail view, but would like to carry over similar functionality while viewing individual images...
    The single image navigation has been brought up here before. I recommend all people new to this discussion read it all the way through. We came a long way and learned a lot of things.

    To do the navigation, (BTW, I wrote the thumb nav) you would have to complete recode what happened when you click on a thumbnail. It does a SQL query that says:

    PHP Code:
    $result mysql_query"SELECT photo_caption,photo_filename 
    FROM gallery_photos WHERE photo_id='"
    .addslashes($pid)."'" ); 
    You are only retrieving 1 photo from the database, so there is nothing to nav thru. I looked at trying to fix this, but simply was not a good enough coder to do so. Maybe someone here will step up to the plate.

  22. #172
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Quote Originally Posted by bencallaway_uk

    42 $category_list .=<<<__HTML_END
    43 <option value="$row2[0]" selected>$row2[1]</option>\n
    44 __HTML_END;

    Try
    PHP Code:

    42$category_list 
    .= <<<END 
    43     
    <option value=$row2[0selected>$row2[1]</option>\
    44END

    ensure that the END;

    is the end of the line no spaces after the ;

    and starts at the start of the line.

    also the "" arent needed its only a number going their so thats ok.

    else try
    PHP Code:

    42 $category_list
    [] .= '<option value=$row2[category_id]>$row2[category_name]</option>'
    I would rather use the second option.

    Well thats what i have used mostly

  23. #173
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    some place south
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    gettin there

    cheers for the quick reply.

    got it half working. the add category works.

    but when it comes to editing or deleting the categories are not in the list.


    also how do i delete just one for the images, or edit caption?

    code=


    <?php
    include("config.inc.php");

    if( empty($_POST['action']) )
    {
    // Firstly Lets build the Category List

    $result = mysql_query( "SELECT category_id,category_name FROM gallery_category" );
    while( $row = mysql_fetch_array( $result ) )
    {
    $category_list[] .= '<option value=$row2[category_id]>$row2[category_name]</option>';
    }
    mysql_free_result( $result );

    $category_list = '<select name="categoryid">'.$category_list.'</select>';
    ?>

    <form name="add_category" action="admin.php" method="post">

    <b>Add Category/b><br />
    Name: <input type="text" name="cname" />
    <input type="submit" value="add" name="action" />

    </form>

    <br /><br />

    <form name="edit_category" action="admin.php" method="post">

    <b>Edit Category/b><br />
    New Name: <input type="text" name="cname" />
    <?php echo($category_list); ?>
    <input type="submit" value="edit" name="action" />

    </form>

    <br /><br />

    <form name="delete_category" action="admin.php" method="post">

    <b>Delete Category/b><br />
    <?php echo($category_list); ?>
    <input type="submit" value="delete" name="action" />

    </form>


    <?php
    }
    else
    {
    if( strcasecmp($_POST['action'], "add")==0 && !empty( $_POST['cname'] ) )
    {
    add_category($_POST['cname']);
    }
    else if( strcasecmp($_POST['action'], "edit")==0 && !empty( $_POST['cname'] ) && !empty( $_POST['categoryid'] ) )
    {
    edit_category($_POST['categoryid'], $_POST['cname']);
    }
    else if( strcasecmp($_POST['action'], "delete")==0 && !empty( $_POST['categoryid'] ) )
    {
    delete_category($_POST['categoryid']);
    }
    else
    {
    echo("Action not understood"); exit;
    }

    echo("Process completed!");
    }


    // the functions here

    function edit_category($category_id, $new_name)
    {
    mysql_query("
    UPDATE gallery_category SET
    category_name = '" . addslashes($new_name) . "'
    WHERE category_id = '" . addslashes($category_id) . "'");
    }
    function add_category($category_name)
    {
    mysql_query("
    INSERT INTO gallery_category (
    category_name
    ) VALUES (
    '" . addslashes($category_name) . "'
    )");
    }

    function delete_category($category_id)
    {
    global $images_dir;

    $result = mysql_query("
    SELECT photo_filename
    FROM gallery_photo
    WHERE photo_category='" . addslashes($category_id) . "'");
    while ($row = @mysql_fetch_array($result)) {
    unlink($images_dir . '/' . $row[0]);
    }

    mysql_query("
    DELETE FROM gallery_photo
    WHERE photo_category='" . addslashes($category_id) . "'");

    mysql_query("
    DELETE FROM gallery_category
    WHERE category_id='" . addslashes($category_id) . "'");
    }

    ?>



    thanks again.

  24. #174
    Anonymous
    SitePoint Community Guest
    i get a lot of error messages like:
    "Notice: Undefined index: number_of_fields in C:My DocumentsMy Websitepreupload.php on line 14

    Notice: Undefined variable: photo_category_list in C:My DocumentsMy Websitepreupload.php on line 22"

    and others on the other pages...
    maybe i'm not doing somthing right... can someone help?

    Written by anyak

  25. #175
    SitePoint Member
    Join Date
    Oct 2003
    Location
    York, UK
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey anyak,

    could you show us the code that the errors are coming from please? it will make it a lot easier for someone to help you out...

    the undefined variable is easy tro fix... just put
    Code:
    $photo_category_list = ""
    at the top of your php code...

    the undefined index will most likely be something to do with an array... could you show us line 14 and any relevant lines around it please?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •