I'm learning PHP and MySQL, and I'm trying to create a simple online pastebin website. I want to create both anonymous and logged in user pastes.

I created a 'user' table with uid, name and password columns, and a 'pastes' table with pid, paste and uid columns. In a viewpaste.php page, the paste ID is used as a GET parameter, to retrieve stored pastes.

How can I link the two tables together for logged in users only? I added the uid on the pastes table for that purpose. I tried setting uid in pastes as a foreign key referencing the uid in user table, but that doesn't seem to be working (gives error for anonymous pastes). Any pointers would be great.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.