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.

[QUOTE=lesliez;18758]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.[/QUOTE]

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 –

Hi Albert,

Is

– field from your database –

suppose to be a block of SQL command?

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


$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();
}

Hi Albert,

I got it. Thanks.

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?

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.

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.

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.

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?

[QUOTE=lesliez;18802]
Any suggestion [/QUOTE]

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.

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…

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…

With your attitude you will not be happy with any system … Beautiful, that we have cleared that up.

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,

I don’t understand why is it so hard for you to realise I have watched all the videos and this is not the first time I told you this. If you don’t have the interest to help up newbie/new comer/non-programmer, then just be it. I can see it now with what you present and what RHS has present.

As I said, if a community senior are so hard to accept new comer/newbie/non-programmer, then this is it. The SC community that will never grow.

RHS, if your english is good enough, then you should be realise my point is always “community”. I don’t complain system much, as I know clearly each system have it’s strength and weakness.

What I concern is the community, such as Joomla and many more. A friendly and helpful environment even with stupid newbie questions.

But here… Ooooo. If Albert and RHS was SC developer, I guess SC won’t even make it to version 6.

Here is all the time I have for both of you who think you’re a patient and tolerance person. Enjoy your time torturing newbie here.

I feel so good after decided not to return to this forum

What you forget is that we are volunteers. We put a lot of our free time in an attempt to help people out. But sometimes the demands are too high. That has nothing to do with friendlyness, it’s your attitude and nothing else. That’s all I have to say about it.