Student has to view own details

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mankolele
    New Member
    • Sep 2006
    • 63

    Student has to view own details

    How do I restrict a person from seeing evrything that I have on my database to them seeing only their information and products for them to be able to UPDATE,EDIT and DELETE their own only

    Thanx
  • raji20
    New Member
    • Aug 2006
    • 28

    #2
    Originally posted by mankolele
    How do I restrict a person from seeing evrything that I have on my database to them seeing only their information and products for them to be able to UPDATE,EDIT and DELETE their own only

    Thanx
    Use a where condition in the select query where you display the records

    For eg, if the user with the id #2 is logged in , put this id in the session, then the qry will be as

    $sql = mysql_query("se lect * from tableName where id = '".$_SESSION["id"]."'") or die(mysql_error ()) ;

    you need to make sure that the product table has the foriegn key which is the primary key of the users table

    Comment

    • mankolele
      New Member
      • Sep 2006
      • 63

      #3
      Originally posted by raji20
      Use a where condition in the select query where you display the records

      For eg, if the user with the id #2 is logged in , put this id in the session, then the qry will be as

      $sql = mysql_query("se lect * from tableName where id = '".$_SESSION["id"]."'") or die(mysql_error ()) ;

      you need to make sure that the product table has the foriegn key which is the primary key of the users table
      Thanx for the reply.

      but my primary key at the moment is the supp_name I dont have the id as its the foreign key on the product table or do I need to change the table structure to have the id

      Comment

      • raji20
        New Member
        • Aug 2006
        • 28

        #4
        Originally posted by mankolele
        Thanx for the reply.

        but my primary key at the moment is the supp_name I dont have the id as its the foreign key on the product table or do I need to change the table structure to have the id
        yes it will be better if you change the table structure, so that it can have the foriegn key as the user's id in the product table

        Comment

        • mankolele
          New Member
          • Sep 2006
          • 63

          #5
          Originally posted by raji20
          yes it will be better if you change the table structure, so that it can have the foriegn key as the user's id in the product table
          Hi I changed my structure but now adding a product gives me a hassle even though a supplier is registered it does not want to add their products it goes to foreign key constraint errer as if the supplier is not registered.If they are not I know it does that.

          Comment

          • mankolele
            New Member
            • Sep 2006
            • 63

            #6
            Originally posted by mankolele
            Hi I changed my structure but now adding a product gives me a hassle even though a supplier is registered it does not want to add their products it goes to foreign key constraint errer as if the supplier is not registered.If they are not I know it does that.
            Oh I can add the product from the mysql but then how do I define the user_id for it to know which id I am adding the products to. Can I use '".$_SESSION["user_id"]."' even though I am not using them anywhere in my coding???

            Comment

            • raji20
              New Member
              • Aug 2006
              • 28

              #7
              Originally posted by mankolele
              Oh I can add the product from the mysql but then how do I define the user_id for it to know which id I am adding the products to. Can I use '".$_SESSION["user_id"]."' even though I am not using them anywhere in my coding???

              Whenever the user enters the site, he/she might be adding products to the shopping cart at that time you need to assign the session id (session_id ) or currernt time() as the cart id and this will be stored in the session value, say $_SESSION["CART_ID"],
              Now you'll be insetring a new record in the products table each time whenever user clicks on the add to cart, with the session cart id ($_SESSION["CART_ID"]) maintaing in the table. Now whenever you are inserting the product in the table, you need to insert the product information, session cart id ($_SESSION["CART_ID"]), and the user id , again the user id is also going to come from the session $_SESSION["USER_ID"],if the user is logged in , if the user is not logged in leave it as empty, at the time of checkout you'll ask the user to login to the site, now put the user id in session and update the product table, for eg,

              update product_table set user_id = '$_SESSION["USER_ID"]' where cart_id=$_SESSI ON["CART_ID"];

              Hope this is clear to you, if you have any queries get back to me

              Comment

              • mankolele
                New Member
                • Sep 2006
                • 63

                #8
                Student has to view own details

                After logging on a Student has to view their school progress and test marks, how do I make sure that they are restricted to only their information and not of fellow mates? Coz now everybody sees everybody's marks which is not acceptable.

                Thanks in advance

                Comment

                • ronverdonk
                  Recognized Expert Specialist
                  • Jul 2006
                  • 4259

                  #9
                  When I remember correctly, you had already asked that question (and it was answered) in your own thread thread merged into this one

                  Are you asking an almost identical question here?

                  Ronald :cool:

                  Comment

                  • mankolele
                    New Member
                    • Sep 2006
                    • 63

                    #10
                    I never understood which is the reason why I am trying again now

                    Comment

                    • iam_clint
                      Recognized Expert Top Contributor
                      • Jul 2006
                      • 1207

                      #11
                      Duplicate posts are kind of frowned upon....

                      Assuming your using a Database such a SQL server, Mysql.

                      you need to add a where statement.. Ex.

                      SELECT * FROM Database
                      WHERE student_id = 1

                      student_id should beable to be retrieved from the session when the user logs in, if you don't have user_id's or session_id's you need to think for alittle bit and get some of this stuff coded in.

                      Comment

                      • ronverdonk
                        Recognized Expert Specialist
                        • Jul 2006
                        • 4259

                        #12
                        Originally posted by mankolele
                        I never understood which is the reason why I am trying again now
                        If you don't understand the code shown to you in this forum, you must either tell the poster that you don't understand it or try to upgrade your PHP knowledge to a level where you can understand it.

                        But do not post the same question again and again. People get tired over that, because it distracts their attention, away from other members who also have problems.

                        Ronald :cool:

                        Comment

                        • mankolele
                          New Member
                          • Sep 2006
                          • 63

                          #13
                          Originally posted by ronverdonk
                          If you don't understand the code shown to you in this forum, you must either tell the poster that you don't understand it or try to upgrade your PHP knowledge to a level where you can understand it.

                          But do not post the same question again and again. People get tired over that, because it distracts their attention, away from other members who also have problems.

                          Ronald :cool:
                          Oh so I am stupid and don't have a problem.

                          THANKS FOR THAT never liked you.

                          Comment

                          • Banfa
                            Recognized Expert Expert
                            • Feb 2006
                            • 9067

                            #14
                            Originally posted by mankolele
                            Oh so I am stupid and don't have a problem.

                            THANKS FOR THAT never liked you.
                            There is no need for this kind of beligerant post.

                            Abusive behaviour is not tolerated on these forums and any further abusive behaviour will be met with swift action.

                            You have stated yourself that you did not understand the answer that was originally provided for you.

                            The reply that you either "say what it is you don't understand" or "attempt to learn more about php so you can better understand the original reply" is not unreasonable. Either course of action is likely to lead you to a solution.

                            What wont lead you to a solution is name calling and refusing to provide requested information about your problem.


                            I am going to merge this thread with the original thread and then I suggust you

                            1. Appologise

                            2. Give a more indepth description of what it is you don't understand.


                            Banfa
                            Community Administrator

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #15
                              Originally posted by mankolele
                              Oh so I am stupid and don't have a problem.

                              THANKS FOR THAT never liked you.
                              Come on mankolele, just apologize to Ronnie there and let's continue to help each other out.

                              Comment

                              Working...