This topic is locked

How do I create a field with Registered Users Already in it.

4/13/2008 21:51:11
PHPRunner General questions
B
bochaka author

How Do I ensure that Registered users have their Name and email address that they used to register, automatically added to any new post that the user might add, and which they cannot remove from the post.

I have 2 tables one called breeders and the other called litter details, my club members come in and add their litter details ,but i need to make sure that they are not masquerading as somebody else.The registration process works fine but at the moment once inside, the breeder can put any name and email address into the fields, so i need to change the setup so after they login and press the add button their name and email appear automatically on the form that they fill in and they cannot edit or delete the name and email fields.Any code will be of great help as i am a total newbie.

R
ringlis1 4/13/2008

Hello there,
I am new here, but, this should help you.
When your at the visual editor, you can double click on the field you want to pre-populate. I use the lookup wizard and then in the default value I enter $_SESSION["UserID"] I use the lookup wizard to display the record name and just store the userID, which will save database space.
Hope this is what you needed.

B
bochaka author 4/13/2008

Hello there,

I am new here, but, this should help you.
When your at the visual editor, you can double click on the field you want to pre-populate. I use the lookup wizard and then in the default value I enter $_SESSION["UserID"] I use the lookup wizard to display the record name and just store the userID, which will save database space.
Hope this is what you needed.



HI

I TRIED THAT and put it in the default area but i get a dropdown box with PLEASE SELECT in it and no values, I also tried using your code in the read only setting , I get a blank area, this suggests to me that I am on the right track but it may not be getting my users name, is there some code missing that tells where to get the user name value from.

I will be back i about 10 hours as it is 5am here, gotta get some sleep.Ilook forward to your and anybody elses reply.

R
ringlis1 4/14/2008

The userID is going to be unique to your database, so you may be using a different text for this.
Did you also set up your password page? This is where the script gets what your using for the userID.

J
Jane 4/14/2008

Hi,
you can do the following:

  1. save username and email of logged user in the $_SESSION variables in the AfterSuccessfulLogin event on the Events tab and then use these variables as default value on the "Edit as" settings dialog on the Visual Editor tab.

    Here is a sample code for event:
    global $conn;

    $str = "select Name,Email from TableName where username='".$_SESSION["UserID"]."'";

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

    $data = db_fetch_array($rs);
    $_SESSION["Name"] = $data["Name"];

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



where Name, Email and username are your actual field names. TableName is your actual table name.
2. setup these fields as readonly on the "Edit as" settings dialog on the Visual Editor tab.

B
bochaka author 4/14/2008

Hi,

you can do the following:

  1. save username and email of logged user in the $_SESSION variables in the AfterSuccessfulLogin event on the Events tab and then use these variables as default value on the "Edit as" settings dialog on the Visual Editor tab.

    Here is a sample code for event:
    where Name, Email and username are your actual field names. TableName is your actual table name.
  2. setup these fields as readonly on the "Edit as" settings dialog on the Visual Editor tab.


So do i need to make a new field called username and do i put parenthesis around the TableName and also around Name,Email in the line ."'";

J
Jane 4/14/2008

Hi,
you need to replace TableName, Name, Email and username with your actual table and field names.

B
bochaka author 4/14/2008

Hi,

you need to replace TableName, Name, Email and username with your actual table and field names.



Hi , do the names go inside"" or just typed without being inside""

J
Jane 4/15/2008

Don't add any quotes. You need to replace field names only.

B
bochaka author 4/15/2008

Don't add any quotes. You need to replace field names only.



Hi, I dont have a field called username, should I have created one.

My fields are name and email, so i am a little confused by the inclusion of the one called username in your code, should i change it to name

Thank you for you patients so far.

B
bochaka author 4/15/2008



Hi, I dont have a field called username, should I have created one.

My fields are name and email, so i am a little confused by the inclusion of the one called username in your code, should i change it to name

Thank you for you patients so far.



Here is the code i entered, i put it into the after sucessfull login page
global $conn;

$str = "select breedername,email from breeders where breedername='".$_SESSION["UserID"]."'";

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

$data = db_fetch_array($rs);
$_SESSION["breedername"] = $data["breedername"];

$_SESSION["email"] = $data["email"];
it crashes on attempted login with the message

Error type 256

Error description Table 'cormac_pupsie2.breeders' doesn't exist

URL germanshepherdpups.ie/data/login.php?

Error file /home/cormac/public_html/data/include/dbconnection.php

Error line 26

SQL query select * from `_breeders` where `breedername`='bonner' and `pass`='8a67bdb3f940f2b2bda687f34559dba8' and `active`=1
I am not too sure where the active 1 bit is coming from. when the code is not in the event page the thing works but just doesnt prefill the fields, also should I put those last two lines into the view as default boxes and set to read only and take them from the events page.

J
Jane 4/16/2008

Hi,
it's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and send to support@xlinesoft.com a URL to your pages along with instructions on reproducing this error.

I'll find what's wrong with your project inspecting it at Demo account site.

B
bochaka author 4/16/2008

Hi,

it's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and send to support@xlinesoft.com a URL to your pages along with instructions on reproducing this error.

I'll find what's wrong with your project inspecting it at Demo account site.



I have done that two days ago but not heard back yet, i will resend it again now

B
bochaka author 4/17/2008



I have done that two days ago but not heard back yet, i will resend it again now



Hi Jane

Did you have a look at it yet.

J
Jane 4/17/2008

I haven't received link to your project on the Demo Account server.

Please re-send it.

B
bochaka author 4/17/2008

I haven't received link to your project on the Demo Account server.

Please re-send it.



Hi Jane

I have sent it again and marked the email for your attention.Thanks.

B
bochaka author 4/18/2008



Hi Jane

I have sent it again and marked the email for your attention.Thanks.



Hi Jane

I tried iout the demo site but got an error, i have sent you the details via email.

The error is

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ']' in C:\UserAccounts\www\bochaka_bochaka_com\april15_d_20080414092447\_breeder_add.php on line 243

Sergey Kornilov admin 4/18/2008

Answered to your email

B
bochaka author 4/18/2008

Answered to your email



Hi, I just sent you another,