每个User_ID的个人资料图片 [英] Profile Picture For Each User_ID

查看:54
本文介绍了每个User_ID的个人资料图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家晚上好,

我有一个有关允许每个用户ID上传个人资料图片的问题.我正在建立一个动态网站,允许用户注册并拥有自己的个人资料.在他们的个人资料中,他们可以上传个人资料图片.我的数据库中有很多表,包括用于注册的表,该表具有user_id作为主键,以及用于上传个人档案图片的表,其中具有picture_id作为主键,而user_id作为外键.

现在的问题是:登录时,将user_id插入数据库,但是当我进入个人资料页面上传图片时,出现用户ID不存在"错误(我添加了该错误消息).然后,我必须转到个人资料图片表,并将user_id手动添加到表中,然后上传个人资料图片.

所以,我的问题是,当用户登录并插入注册表中的user_id(主键)时,有没有办法在个人资料图片表的user_id(外键)中更新和插入相同的id,而无需手动做吗?这样每个用户都可以拥有自己的个人资料图片.

PS:我不会将图片本身上传到数据库中,而是将图片的路径插入数据库中.

感谢您的帮助.
谢谢!

Good evening all,

I have a question regarding allowing each user id upload a profile picture. I''m building a dynamic website that allows users to register and have their own profile. In their profile, they can upload a profile picture. I have many tables in my database, including a table for registration which has the user_id as the primary key, and a table for uploading profile pictures which has picture_id as the primary key and user_id as the foreign key.

Now here''s the problem: When I login, the user_id is inserted into the database, but when I go to the profile page to upload a picture, I get a "user id does not exist" error (I added that error message). Then I''d have to go to the profile picture table and manually add the user_id to the table and then the profile picture gets uploaded.

So, my question is, when a user logs in and the user_id(primary key) in the registration table is inserted, is there a way to also update and insert that same id in the user_id(foreign key) in the profile picture table without doing it manually? So that each user can have his own profile picture.

PS: I''m not uploading the pictures themselves into the database, i''m inserting the path of the image into the database.

I appreciate any help.
Thanks!

推荐答案

首先,当用户登录时,为什么需要在用户数据表中插入一条记录?您仅应在用户注册后插入该记录.并在用户随后每次登录时重复使用相同的记录.

您可以按照将数据插入到用户表的相同方式,将记录插入到个人资料图片表.编写mysql_query将数据插入到个人资料图片表中,并将其放置在mysql_query之后,以将记录插入到用户表中.

可是等等.假设您具有用户和个人资料图片的一对一映射,为什么还要将个人资料图片存储在单独的表中.当然,您在两个表中具有相同的键.将个人资料图片中的所有列移动到用户表.在此之前,Google进行数据库规范化"并读取弹出的一些链接,因为这是错误的规范化. (当然,这是假设您已经与用户和个人资料图片进行了一对一的映射.如果没有,请忽略.)
First of all, why would you need to insert a record into user data table when the user LOGS IN? You should insert that record only when the user SIGNS UP. And reuse the same record every subsequent time the user logs in.

You can insert a record to the profile picture table the same way you inserted data to the user table. Write a mysql_query to insert that data into profile picture table and place it after the mysql_query to insert a record to users table.

But wait. Assuming you have one-to-one mapping with user and profile picture, why would you ever want to store the profile picture in a separate table. Surely you have the same keys in two tables. Move all the columns in the profile pictures to the users table. And before doing that, Google "database normalization" and read some of the links that pop up, because this is BAD NORMALIZATION. (Of course this is assuming you have one-to-one mapping with user and profile picture. If not, ignore.)


这篇关于每个User_ID的个人资料图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆