SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot Dreamweb Designs's Avatar
    Join Date
    Nov 2005
    Location
    Detroit, MI.
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    uploading content to multiple "categories" on my page

    Hello,

    over the past couple days I have ran into some problems, and I think this is the last one I am having.

    I have different categories on my page (ie: Free Phones, Motorola Phones, Razr Phones, ect)

    What I want to be able to do, is in my upload form which uploads the image,description,name,link to the database, i want it to also be able to checkbox which categories i put it in, and they automatically show on those pages.

    I am not sure if its just seperate tables i need to create for each category, or if I just add extra fields or what. im really confused to this part.

    here is my scripting for the upload form:

    HTML:
    Code:
    <form enctype="multipart/form-data" action="ygac-insert.php" method="POST" /><br />
    Name: <input type="text" name="name"><br />
    Description: <input type="text" name="description"><br />
    Link: <input type="text" name="link" /><br />
    Image: <input type="file" name="image"><br />
    <input type="hidden" name="id"><br />
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <input type="submit" value="submit">
    </form>
    PHP:
    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","username","password");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("yougotacall"$con);

    $uploaddir '/home/.fury/php/uploads/';
    $uploadfile $uploaddir basename($_FILES['image']['name']);

    $imagedir 'uploads/';
    $imagefile $imagedir basename($_FILES['image']['name']);

    echo 
    '<pre>';
    if (
    move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) {
       echo 
    "File is valid, and was successfully uploaded.\n";
    } else {
       echo 
    "Possible file upload attack!\n";
    }

    echo 
    'Here is some more debugging info:';
    print_r($_FILES);

    $sql="INSERT INTO yougotacall (image, name, description, link, id)
    VALUES
    ('
    $imagefile','$_POST[name]','$_POST[description]','$_POST[link]','$_POST[id]')";

    if (!
    mysql_query($sql,$con))
      {
      die(
    'Error: ' mysql_error());
      }
    echo 
    "1 record added";
    print 
    "</pre>";

    mysql_close($con)
    ?>
    Any help with this is greatly appreciated. You guys are awesome with this stuff, and I've learned a lot in the past few days from guys on here.

    Thanks again.
    with great sacrifice comes great rewards

  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Location
    Atlantis
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have small number of categories, you can define them as fields in your items table. If they are dozens, a matching table for matching categories with items are more efficient.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A combination of both would be the best solution IMHO.

    Add a field in your yougotacall table and called it 'cat_id' and then create a new table called categories with the following fields:

    id | cat_name
    Soren Beck Jensen

    http://www.automaticbacklinks.com - Free link exchange network
    http://www.notwebdesign.com - Joomla web design in Spain

  4. #4
    SitePoint Zealot Dreamweb Designs's Avatar
    Join Date
    Nov 2005
    Location
    Detroit, MI.
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, then i would just call from those table's / categories on the respective pages right?

    would the cat_id be called to pull from the ID of the category table? or do i just do like this

    Category Page:

    call for id | cat_name ?

    sorry, im really confused. i haven't slept in almost 2 days.
    with great sacrifice comes great rewards

  5. #5
    SitePoint Zealot Dreamweb Designs's Avatar
    Join Date
    Nov 2005
    Location
    Detroit, MI.
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can anyone shed some light on this for me?
    with great sacrifice comes great rewards

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Location
    Atlantis
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    CAT
    cat_id / cat_name

    ITEMS
    item_id / item_name / item_description / item_image

    CROSSTABLE
    cat_id / item_id


    When browsing specific category.
    - Make call to Crosstable with WHERE cat_id='$currentcategoryvariable'
    - Get item_id's from crosstable call
    - Loop through item_ids and make call to ITEMS table for details for each.


    Hope i did understand right on what you are asking for.

  7. #7
    SitePoint Zealot Dreamweb Designs's Avatar
    Join Date
    Nov 2005
    Location
    Detroit, MI.
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Aras
    CAT
    cat_id / cat_name

    ITEMS
    item_id / item_name / item_description / item_image

    CROSSTABLE
    cat_id / item_id


    When browsing specific category.
    - Make call to Crosstable with WHERE cat_id='$currentcategoryvariable'
    - Get item_id's from crosstable call
    - Loop through item_ids and make call to ITEMS table for details for each.


    Hope i did understand right on what you are asking for.

    let me see if i get this right.

    Make the table: CAT
    Make the fields: cat_id / cat_name

    Make the table: ITEMS
    Make the fields: item_id / item_name / item_description / item_link / item_image

    Make the table: CROSSTABLE
    Make the fields: cat_id / item_id
    ---------

    correct?

    Now, when I do this: - Make call to Crosstable with WHERE cat_id='$currentcategoryvariable' I am totally lost. lol. I apologize for not understanding, I just am not too far into php as of yet (im learning though).

    If someone could explain this a little further i would greatly appreciate it.
    with great sacrifice comes great rewards


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
  •