Announcement

Collapse
No announcement yet.

How to set value from database field as global variable?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to set value from database field as global variable?

    Hi,

    I need to set a field value from the logged user table as global variable.

    I assume I suppose to set the global variable at login app event.

    But I don't know how to get the correct field/row data.

    Its a field in the "user" table generated by Security Module, its a new field I added manually and set auto increment. I need the number of the logged user.

    Please advice, thank you.

  • #2
    Originally posted by lesliez View Post
    Hi,

    I need to set a field value from the logged user table as global variable.

    I assume I suppose to set the global variable at login app event.

    But I don't know how to get the correct field/row data.

    Its a field in the "user" table generated by Security Module, its a new field I added manually and set auto increment. I need the number of the logged user.

    Please advice, thank you.
    You have to adjust the sql which is retrieving data from the usertable and append yur field to it. Then you retrieve the value as the others and apply that to your global variable. Global variables are declared between []

    So you get a line like:
    [glob_myvar]= -- field from your database --
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      Hi Albert,

      Is

      -- field from your database --

      suppose to be a block of SQL command?

      Comment


      • #4
        for demonstration purpose only a snippet from my login code using globals;

        Code:
        $slogin = sc_sql_injection({uid});
        //$spswd = sc_sql_injection(md5({pwd}));
        $spswd = sc_sql_injection({pwd});
        $sql = "SELECT 
        		dohmpersid,
                herkomst,
                userrole,
        		active 
                FROM dohmuser 
        	    WHERE userid = $slogin
                AND active = 'Y' 
        		AND password = ".$spswd."";
        	
        sc_lookup(rs, $sql);
        	
        if(count({rs}) == 0)
        {
        	sc_log_add('[1] login Fail', {lang_login_fail} . {uid});
        	sc_error_message({lang_error_login});
        	sc_error_exit();
        }
        
        if({rs[0][3]} == 'Y')
        {
        	[glob_user]={rs[0][0]};		
        	[glob_rolelist]={rs[0][2]};
        	[glob_herkomstlist]={rs[0][1]};
        	[glob_loguser]={uid}.':'.{rs[0][0]};
        }
        else
        {
        	sc_error_message({lang_error_not_active});
        	sc_error_exit();
        }
        Albert Drent
        aducom software netherlands
        scriptcase partner, reseller, support and (turn-key) development
        www.scriptcase.eu / www.scriptcase.nl

        Comment


        • #5
          Hi Albert,

          I got it. Thanks.

          Comment


          • #6
            Hi Albert,

            I put the following code into Form Event onLoad

            [v_ownerid] = "SELECT
            ownerid
            FROM
            users
            WHERE
            (login = '[usr_login]')
            ORDER BY
            ownerid";

            sc_alert("[v_ownerid]");
            But when I run the form with security enable, no alert prompt out. [v_ownerid] has no value.

            May I know what have I done wrong?

            Comment


            • #7
              Hi Lesliez. It's time you look at the tutorial movies. Global variables are of type in or type out. If they are of type in then by default they expect a value. When these are not available SC will ask for them at runtime, but only while your in development mode. Go to application -> globals and change type and the message will go away.
              Albert Drent
              aducom software netherlands
              scriptcase partner, reseller, support and (turn-key) development
              www.scriptcase.eu / www.scriptcase.nl

              Comment


              • #8
                Hi Albert,

                I don't understand why you describe about types of Global Variable. I know Global Variable have In and Out. I have set it to Out before I make this post.

                Getting a variable input field in runtime is not what I'm asking. I have no problem with that.

                Now what I need is to assign the "ownerid" value to [v_ownerid].

                The sample code I posted previously is what I have in Form Event onLoad hoping to assign the value of "ownerid" to [v_ownerid]. But it turn out nothing has been assigned. So I need to know what I did wrong and what should I do to achieve my goal. Please advice, thank you.
                Last edited by lesliez; 11-05-2013, 02:36 PM.

                Comment


                • #9
                  Mmm, I think I was too hasty. You are assigning a sql statement to a variable. But there's nowhere any access to the database. sc_alert is not usable in the onload event as there's no webaccess. Rembember that alert messages are to be done by javascript on the client and the onload is running on the server. So if you want to look at the generated code you could try to echo the value: echo 'this is the text' and it will appear somewhere on your form. But if you need to test sql statments then make your access like my sample, go to application -> settings and set the debug checkboxes to true. Then SC will display each and every sql statement before executing. This way you are able to test your database access.

                  If you look at the helpfile and macro's you will find in which events the macro's are valid. You would have seen that sc_alert is not valid in onload.
                  Last edited by aducom; 11-05-2013, 03:32 PM.
                  Albert Drent
                  aducom software netherlands
                  scriptcase partner, reseller, support and (turn-key) development
                  www.scriptcase.eu / www.scriptcase.nl

                  Comment


                  • #10
                    Hi Albert,

                    sc_alert is not the function that I want, I just use it to display the value.

                    Any suggestion on how to assign the value to the global variable? Such as use any macro to get the data and etc?

                    Comment


                    • #11
                      Originally posted by lesliez View Post
                      Any suggestion
                      Look first at php for beginners (here or here, or search yourself at google). Your problem has nothing to do with SC. You simply lack the background knowledge to program. Not bad and everyone can learn it, but it too much to ask to give you here a programming course.
                      Best regards: - Reinhard -

                      I use ScriptCase 8 Enterprise Edition, Version 8.(latest)

                      Comment


                      • #12
                        This stupid forum is filled with stupid non-helpful community act nothing better than the support or whatever.

                        SC will die because of its support and its community mindset...

                        If newbie non-programmer questions is not allowed, close the fucking forum then...

                        Comment


                        • #13
                          I have solved my problem and got my field receive default value of my owner field.

                          I found out how simple it is to solve the problem. If I were a senior in SC, I'll be more than happy to point out the error in newbie's code and just offer a little help to correct the code and some simple explanation.

                          But too bad... The SC community is too closed minded and not willing to help newbie. A community that are not willing to help build up new user/non-programmer, this community will not grow far.

                          And now I know why there is not a single Book in Amazon with Scriptcase title.

                          Good luck to this community...

                          Comment


                          • #14
                            With your attitude you will not be happy with any system ... Beautiful, that we have cleared that up.
                            Best regards: - Reinhard -

                            I use ScriptCase 8 Enterprise Edition, Version 8.(latest)

                            Comment


                            • #15
                              I think I have had a lot of patience, but I don't see why I had to invest that much time in to someone who refuses to watch educational video's, look into the helpfile and expect that every volunteer on this forum will run like hell on every question you ask. I don't mind that you're a newbee, I'm glad to help, but you are looking for the most easy way. Don't look, just ask. I don't have time for that. Regarding your attitude, yes, I agree on RHS. I don't think you will reach much on other forums. But that's your problem.
                              Albert Drent
                              aducom software netherlands
                              scriptcase partner, reseller, support and (turn-key) development
                              www.scriptcase.eu / www.scriptcase.nl

                              Comment

                              Working...
                              X