image can be uploaded but I cant an upload an image for specific user

same table but with different IDs .I make two PHP page for user and admin so I can login as user or admin

This would be an input in the upload form. You would build a select/option menu to let the admin(istrator) select the user id that the image will be associated with.

In the form processing code, after you have validated all the submitted form data, you would store the submitted user id in the row that’s inserted into the qr table.

When you display the qr image for the currently logged in user, you would get the user id from the session variable and use it in the WHERE term in the SELECT query to find the matching row in the qr table, if any.

1 Like

Mabismad beat me to the Reply button but I will post what I wrote anyway.

So you’ve got a DB table for “users”. This table should have field that is of type int that is set as the PRIMARY KEY and AUTO_INCREMENT. This field might be called id or user_id but the point is this will be the unique user ID that identifies the user. All your pages should have session_start(); at the top before anything is sent to the browser. This will allow you save important information about the user when they log in as you normally are making a query to check their login information, so grab fields about the user you want e.g. id, level (which could hold ‘Admin’ or ‘User’) and set these values to session with the query result. As an example:

$_SESSION['secure_id'] = $row['id'];	
$_SESSION['secure_level'] = $row['level'];

Now any displays or actions can be based on this information. For example saving uploaded files can now be saved with the user ID and as mentioned you can query for images that belong to this user as their $_SESSION['secure_id'] holds that information and identifies the user viewing the page.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.