Jump to content

Recommended Posts

Ok i was wondering something

mysql_query("INSERT INTO userdata (Username, Username2) 
VALUES ('$user2', '$user1')");

 

I am inserting data using this code into my userdata table in mysql.

and now i have just crossed a problem.

 

The problem is that Value $user2 is going to be the same sometimes.

When this code is initiated and there is information that is the same in the database.. it doesnt make a new area with the information.

 

For example.

 

The datatabe userdata looks like this..

Username, Username2

Bobby123  Bobbiesbuddy123

 

Then Bobby 123 wants another buddy

i want to be able to add another column right under that

Bobby123 Bobbiesbuddy123-2

 

But when any part is the same it doesnt submit.

 

is there a way around this. or am i just doing this the wrong way?

Link to comment
https://forums.phpfreaks.com/topic/72999-solved-insert-into-function/
Share on other sites

Yea all the buddies are users as well. its a process they find another user, and then click add buddy. and the user is added on their buddy list. then going back to the buddy list it will look at all the information that is in my datatable.

 

ok so username wants username2 as their buddy.

they click add to buddy

it then writes the data in the database that includes

First guy.  His buddy

username  username2

 

if username want username3 to be his buddy also.

then it will write with both in the table

username  username2

username  username3

 

then when they want to view all of their buddies. the php document searches through the userdata table.

and finds all of His buddy information that is listed next to First guy. and it will display it.

 

I just want to know if there is code that can make it write it like this in the database. or if i have to do this another way

You want to add a Buddy table.  It will look something like this.

 

Buddy
----------------
ID    UserID    BuddyID
1        12       13
2        12       2
3        12       14
4        14       13
5        14       12

 

UserID points to the ID field in the User table, and BuddyID also points to the ID field in the User table.

 

In the example I gave above it might be something like this

 

User(12) requested User(13) as a buddy

User(12) requested User(2) as a buddy

User(12) requested User(14) as a buddy

User(14) requested User(13) as a buddy

User(14) confirmed User(12) as a buddy

 

If that's your whole table, the only buddies in the database are users 12 and 14.

 

You could simply have it that if someone requests a buddy, it's granted, so record 5 in the table is unnecessary and redundant, but that would probably be more complex.  I suggest the previous method.

 

mysql_query("INSERT INTO userdata (Username, Username2) 
VALUES ('$user2', '$user1')");

 

this is the code. for the .php file. i already have the variables for user2 and user1.

 

my database currently is

 

table= userdata

           

            Username    varchar  40

            Username2  varchar  40

 

Thats my current database for this.

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.