Forum Moderators: coopster
I would like to restrict every user to deleting and editing the rows of information that they themselves have posted.
How would I go about doing this?
I have searched for quite a while and I am unable to find such a tutorial or a ready example. Any links would be appriciated.
The answer to your own question is already there. You see, you "would like to restrict every user to deleting and editing the rows of information that they themselves have posted." That means you need to store the unique user's id with the posted message so you can identify who posted it. Then, when you display it you can check the stored user id with the userid of the person that is logged in. If they match, you allow certain operations. If not, you don't even display the operations.
Also, whether it is good or bad design, is this even possible?
Every time a new user is registered, create a new table with standard fields that all user table have and then name it accordingly by using the user id
CREATE TABLE personal + '$id'( id INT NOT NULL AUTO_INCREMENT,or something along those lines. If this can be done where would be a good place to place this command?
PRIMARY KEY(id),
name VARCHAR(30),
email VARCHAR(20));
ALTER TABLE `info` ADD `whoAdded` VARCHAR( 20 ) NOT NULL ;
During any further searchs of the database, you want only those records where the info.whoAdded entry is equal to the id of the current user ($_SESSION['username']) per my suggestion above.
Good luck.
Anyone notice what the reason for this could be?
$result = mysql_query( "SELECT * FROM items" )
or die("SELECT Error: ".mysql_error());
$worked = mysql_fetch_array($result);
$iduser = $worked['iduser'];
if ($iduser == $_SESSION['valid_id']) {
$num_rows = mysql_num_rows($result);
print "<br><br>There are $num_rows records.<P>";
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";
}
When I try to display the items I use the code that I posted previously. But, it doesn't display any items.. and when the 'if...' is removed all items are displayed.
So I have come to the conclusion that I am unable to grab the value for 'iduser' before i compare to see if it is the same as the value of $_SESSION['valid_id'].. unless you see something else that is not correct in the code I posted?
Actually, come to think of it I am pretty sure that, that is the problem.. I am not able to transfer the value from the field 'iduser' to the variable '$iduser'. Could you possibly suggest how I can get around this?