Results 1 to 5 of 5
  1. #1
    silverglade is offline Senior Member
    Join Date
    Feb 2009
    Posts
    182
    Rep Power
    6

    Default making 2 mysql database fields equal?

    Hi, I have a "id" field as primary key in my "users" table, and I need to make the current user's id equal to the "gallery_user" field in the "images" table. I am trying to link the uploaded images to each user, then when it comes time for the user to view the gallery, they only see their images. Any help on how to do that greatly appreciated. thank you.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default

    You'll need to show us your table structure, mainly how the two tables (users and images) map (foreign keys).
    Also the query used to pull the images from that table that is not returning what you want.

  3. #3
    silverglade is offline Senior Member
    Join Date
    Feb 2009
    Posts
    182
    Rep Power
    6

    Default

    Ok thanks Tolls. here is the query I am using.

    Java Code:
    $currentUser = $_SESSION['myusername'];
     		 $userId =  mysql_query("SELECT id FROM users WHERE username = '$currentUser'");//get current session user name and get ID.
    		    
    		   mysql_query("INSERT INTO images (gallery_user) values ('$userId')");// insert current user id into gallery user.
    		   																		//all based on the session user name

    and here is the table structure.
    -- phpMyAdmin SQL Dump
    -- version 2.8.0.1
    -- phpMyAdmin
    --

    -- Generation Time: Jul 06, 2011 at 03:37 AM
    -- Server version: 5.0.91
    -- PHP Version: 4.4.9
    --
    -- Database: `photo_artists`
    --

    -- --------------------------------------------------------

    --
    -- Table structure for table `images`
    --

    CREATE TABLE `images` (
    `image_id` bigint(20) unsigned NOT NULL auto_increment,
    `gallery_user` bigint(20) unsigned NOT NULL,
    `filename` varchar(255) NOT NULL,
    `mime_type` varchar(255) NOT NULL,
    `file_size` int(11) NOT NULL,
    `file_data` longblob NOT NULL,
    PRIMARY KEY (`image_id`),
    UNIQUE KEY `image_id` (`image_id`),
    KEY `filename` (`filename`)
    ) ENGINE=MyISAM AUTO_INCREMENT=20 DEFAULT CHARSET=latin1 AUTO_INCREMENT=20 ;

    --

    --
    -- Table structure for table `users`
    --

    CREATE TABLE `users` (
    `id` int(11) NOT NULL auto_increment,
    `firstname` varchar(20) NOT NULL,
    `lastname` varchar(50) NOT NULL,
    `dob` date NOT NULL,
    `gender` varchar(10) NOT NULL,
    `username` varchar(20) NOT NULL,
    `password` varchar(60) NOT NULL,
    `email` varchar(20) NOT NULL,
    `activationkey` varchar(100) NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `username` (`username`),
    UNIQUE KEY `email` (`email`),
    UNIQUE KEY `activationkey` (`activationkey`)
    ) ENGINE=MyISAM AUTO_INCREMENT=42 DEFAULT CHARSET=latin1 AUTO_INCREMENT=42 ;

    --
    --

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default

    Um, this is PHP...
    This here is a Java forum.

    But I will say that images insert makes no sense...you aren't inserting an image into the images table at all there.

    Apart from that I don't see the problem. Well, apart from the lack of a foreign key from gallery_user to user id.

  5. #5
    silverglade is offline Senior Member
    Join Date
    Feb 2009
    Posts
    182
    Rep Power
    6

Similar Threads

  1. What is url of my database? MySql WorkBench
    By JavaDreams in forum JDBC
    Replies: 1
    Last Post: 03-14-2011, 10:28 AM
  2. Making a Car Database on Jcreator
    By mcnam4119 in forum Advanced Java
    Replies: 7
    Last Post: 11-01-2010, 06:54 PM
  3. Replies: 2
    Last Post: 02-11-2009, 04:43 AM
  4. Making an Applet use a MySQL Database
    By Bomber_Will in forum Java Applets
    Replies: 5
    Last Post: 11-30-2008, 04:28 PM
  5. connecting to mysql database
    By javagal in forum NetBeans
    Replies: 2
    Last Post: 08-04-2007, 12:36 PM

Posting Permissions

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