Jump to content

need to check db table for author, and if author does not match up, do not allow


bradkenyon

Recommended Posts

I have an update function w/ a query of this:

 

$queryupd = "select * from calendar_items where id = $id";

 

I list the data into the update form, from the table calendar_items.

 

I want to restrict it, so only the person who created the calendar item (event), will be able to update it.

 

I have an author column w/i the calendar_items table.

 

I was thinking something along the lines of:

$queryupd = "select * from calendar_items where id = $id AND author = $HTTP_SESSION_VARS['valid_username']";

 

I wanted it to be almost an if statement, "if you're not the author of this event, then print out msg saying: You do not have the right to edit this event."

Link to comment
Share on other sites

<?php

  // connect

  $sql = "SELECT * FROM calendar_items WHERE id = $id AND author = '{$_SESSION['valid_username']}'";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      // do the update
    } else {
      // display your unauthorised message
    }
  }

?>

Link to comment
Share on other sites

  • 1 month later...

currently it is:

$sql = "SELECT * FROM calendar_items WHERE id = $id AND author = '{$_SESSION['valid_username']}'";

 

would it be?

 

$sql = "SELECT * FROM calendar_items WHERE id = $id AND author = '{$_SESSION['valid_username']}' AND user_level = '1'";

 

user_level being a super user account.

Link to comment
Share on other sites

No, you'd need to make sure that the user trying to access it had the right user level.  Read up on joins.

 

SELECT * FROM calendar_items INNER JOIN users ON users.user_id = {$_SESSION['user_id']} WHERE users.user_level >= calendar_items.user_level;

 

Possibly.  Read up on it and tailor it to your needs.

Link to comment
Share on other sites

@thorpe:

 

Your sql query did the trick, and I made a modification to the update process, only allowing the original author to make an update to their original post.

 

here is the other post (i think you might have a good idea what might be going wrong) i opened up for help, any help would be appreciated.

 

http://www.phpfreaks.com/forums/index.php/topic,211395.0.html

 

Link to comment
Share on other sites

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.