Results 1 to 5 of 5
- 07-06-2011, 08:25 AM #1
Senior Member
- Join Date
- Feb 2009
- Posts
- 182
- Rep Power
- 5
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.
- 07-06-2011, 09:27 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
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.
- 07-06-2011, 09:35 AM #3
Senior Member
- Join Date
- Feb 2009
- Posts
- 182
- Rep Power
- 5
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 ;
--
--
- 07-06-2011, 09:55 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
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.
- 07-06-2011, 10:04 AM #5
Senior Member
- Join Date
- Feb 2009
- Posts
- 182
- Rep Power
- 5
Similar Threads
-
What is url of my database? MySql WorkBench
By JavaDreams in forum JDBCReplies: 1Last Post: 03-14-2011, 10:28 AM -
Making a Car Database on Jcreator
By mcnam4119 in forum Advanced JavaReplies: 7Last Post: 11-01-2010, 06:54 PM -
How to convert access database to mysql database?
By vrk in forum Advanced JavaReplies: 2Last Post: 02-11-2009, 04:43 AM -
Making an Applet use a MySQL Database
By Bomber_Will in forum Java AppletsReplies: 5Last Post: 11-30-2008, 04:28 PM -
connecting to mysql database
By javagal in forum NetBeansReplies: 2Last Post: 08-04-2007, 12:36 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks