0
votes

I am making a page where the user has a login with a session key that matches his username. I want to disable buttons in the last column of a table which doesn't match the session.

My table looks like this : table

I would like to disable the 'Delete' buttons of the rows where field "User" does not match with the session key. It's a simple plain text username/password used for the session (i know, for now its ok)

Here is my PHP script : http://codepad.org/wotpO7Mu

(I know I am not using PDO, and this method of fetching values is deprecated.)

I created my login session this way : https://krisnaordinary.wordpress.com/2010/04/24/creating-a-simple-login-logout-session-using-php/

Can you please help me edit/fix my code to have fields for which I am echo -ing the buttons to be disabled except the one for which the session $_SESSION['usr'] matches the field $row['user_ID'] ?

1

1 Answers

1
votes

Try adding disabled attribute in the button if your session doesn't match

$active = $_SESSION['User'] == $row['user_id'];
echo "<td>".
       "<button class='btn' type='submit' id='1'".
          ($active ? "" : "disabled").">".
          "Delete".
       "</button>".
     "</td>";

I have also went ahead and simplified your code, you don't have to have two buttons, input type=submit is same as button type=submit. You can also have alternate quotes (double inside single or single inside double) to have a cleaner code.