This topic is locked

Using Login OnLoad event

5/14/2007 13:15:06
PHPRunner General questions
D
Dale author

Just a question if this is possible.
I have a table that stores customer advertising purchases. In the advertising purchase I have a blob field that I can upload the users banner to store with the other purchase information.
All works great.
Now what I would like to do, when the login page appears, do a database query on those purchases, load the record id's of purchases with a current banner and then randomly select 3 to display on the login page.
I quickly tried using the Login OnLoad event, using an IF record exists to test to see if I could at least grab one to display on the login page. I get an errors about connection stuff ( this is vague I know, but I would just like to know the general answer to question before I dig deeper. I have tried a couple of variations of the lookup with snippets that do work once logged in.
The question is, should I be able to do a lookup like that from the login page.
If it should work, then I will dig deeper on why I get the errors.
Version. 3.0. Thanks in advance.

Sergey Kornilov admin 5/14/2007

DaleM,
I miss one thing - is the info you trying to get user-specific or not?
When LoginOnLoad event is executed user is not logged in yet and user-specific data cannot be retrieved.

D
Dale author 5/14/2007

Hi Sergey,
No that data will be general, company information from the company table ( address phone number etc )

And then the logo (blob) field from the purchase table.
Every user no matter who can see the result. There will be NO editing of anything.
Im trying to grab all the valid purchases and put the purchase id into a session array.

Then everytime a page refresh or call to another page happens, it could use a little javascript to randomly grab four of the qualified logos and place them in the header and footer sections of the list.
I kind of feel a bit like this might be a dumb question, but it would be a great way to populate the login page with company information and then get this rotating banner display thing to happen.
Thanks for any help here.

Sergey Kornilov admin 5/14/2007

Probably you can post your code and full error message here.

D
Dale author 5/14/2007

Below is the snippet directly from the After Successful Login events and it works fine. Returns the session variables as expected.
global $conn;

$strSQL = "select * from stores, city where (`city`.`city_id` = `stores`.`city_id`)";

$rs = db_query($strSQL,$conn);

$data=db_fetch_array($rs);

$_SESSION["tax1_id"]= $data["tax1_id"];

$_SESSION["tax2_id"]= $data["tax2_id"];

$_SESSION["tax3_id"]= $data["tax3_id"];

$_SESSION["tax1_rate"]= $data["tax1_rate"];

$_SESSION["tax2_rate"]= $data["tax2_rate"];

$_SESSION["tax3_rate"]= $data["tax3_rate"];

$_SESSION["tax1_reg"]= $data["tax1_reg"];

$_SESSION["tax2_reg"]= $data["tax2_reg"];

$_SESSION["tax3_reg"]= $data["tax3_reg"];

$_SESSION["company_name"]= $data["name"];

$_SESSION["company_address1"]= $data["address1"];

$_SESSION["company_address2"]= $data["address2"];

$_SESSION["company_city_id"]= $data["city_name"];

$_SESSION["company_province"]= $data["province_state_code"];

$_SESSION["company_postal_zip_code"]= $data["postal_zip_code"];

$_SESSION["company_phone"]= $data["phone"];

$_SESSION["company_fax"]= $data["fax"];

$_SESSION["company_email"]= $data["email"];

$_SESSION["company_www_url"]= $data["www_url"];
When I place this snippet in the function LoginOnLoad() events
Below is the error I get.
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in c:\phpdev\www\yellowsheet\include\dbconnection.php on line 24
Fatal error: in c:\phpdev\www\yellowsheet\include\dbconnection.php on line 26
Not sure what Im doing wrong. If I can get this one to work, Im sure I can deal with the purchase logo scenario.

Also, there is only one store record by the way.

J
Jane 5/15/2007

Dale,
there is no $conn variable on the LodinOnLoad event. Try to add following code to your event:

$conn = db_connect();

$strSQL = "select * from stores, city where (`city`.`city_id` = `stores`.`city_id`)";

...

D
Dale author 5/15/2007

Thanks Jane,
I was wondering about the exact same thing.

When I selected Check for existing record on the OnLoad event, the sample code did not show the $conn = db_connect(); so I thought I better check before just doing it.
I hope this is not a dumb question but, Is it safe to do this kind of thing from the login page. My sites run under an ssl certificate but by putting this on the login page am I opening myself up for malicious activity of any kind.