1

I have created a comment box successfully using PHP with MySQL. The comment table structure is:

CommentID PK AI
Name
Email
Comment
CommentDateTime

I didn't use an ID to identify the page that is being commented on because I'm using this in only one.

When a user is logged in, the input field for name and email will disappear and the user's name and email that is stored in a session variable will be used. All works fine, but I need to use the user picture that is saved in MySQL to display in the comment box.

Should I add a UserID in the comment table? What if the comment is from a non-user, then should I just add null or 0? I'm quite confused on how to work with comment box using user picture.

3 Answers 3

1

You are trying to relate information from 2 tables since you want to use the picture if the user is registered therefore you need a relation to make the connection between the 2. So yes, you will need the UserID field on the table to make the connection.

If it comes from an unregistered / not-logged user, then you can set USER_ID to null.

If the comment is from a logged user you can then leave the name in the comment table blank and retrieve it from the user table (same goes for the email). This way you will be avoiding data redundancy. (Assume you have a registered user that leaves a ton of comments, without a user id you will be storing his name and email a ton of times that you don't need).

I hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

1

I know this is not exactly what you were looking for, but I find one of these ready made solutions for comments better for my website designs... some our pretty much basic (even primitive) but some are fairly customizable and easy to use! my all time favorite would be flexi comment box

Comments

0

There is one option you ca try for it. You can check user with the email address in the comment table. I think you would have stored email as a unique field. For normal user or unregistered user you can place a default image.This default image will work for all the unregistered users.

1 Comment

But what if the user and the normal user used the same email address? hmm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.