Forums

PHP

This topic is locked

Appending two forms fields to MYSQL row

Posted 01 May 2008 21:06:19
1
has voted
01 May 2008 21:06:19 Will S. posted:
Long story short, I'm using Adobe's Developer Toolbox because I just don't know PHP enough. I've setup a user registration form on my Intranet. The registration form is going to be used for VPN access, and the username has to be in FIRSTNAME.LASTNAME format. This means that I can't allow the visitor to enter his/her own username.

What I'm trying to is append the Fname & Lname form fields to the SQL query before it posts to the database. I see the following line of code is responsible for doing this:

$ins_users->addColumn("Name", "STRING_TYPE", "POST", "Name", "";


Can someone please suggest how I would modify the string to append Fname and Lname instead?

Database rows (naming convention restarted, I know):
Name = username
Fname = First name
Lname = Last name

Thanks in advance,
Will

Replies

Replied 09 May 2008 05:10:45
09 May 2008 05:10:45 no one replied:
yes ...... i need this solution too.
like a user code is combination from country_code + postal_code + auto increment id

help me please!!
need urgent
Replied 12 May 2008 11:42:25
12 May 2008 11:42:25 no one replied:
no reply <img src=../images/dmxzone/forum/icon_smile_sad.gif border=0 align=middle>
Replied 12 May 2008 12:39:18
12 May 2008 12:39:18 Alan C replied:
Hi Guys,
I didn't respond earlier as I don't know anything about the Developer Toolbox - I'm a lifelong coder <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

in PHP there is a string concatenation operator . (the full stop or period - depending which side of the water you are), so you can say something like . . .

$username=$Fname.$Lname;

Then line you quoted has -&gt; in it, which means it's a method within an object, I've not seen that before, but if you save a backup copy then try altering the code you can always go back.

that assumes that first name and last name and in variables $Fname and $Lname respectively

PHP defines variables as you use them, so you don't need declarations before you use them - but that does mean you need to be careful with your typing, also it's case sensitive, so $Fname and $fname are different variables. Don't try to have spaces in variable names or you will get errors, instead use underscores like $F_name (apologies if I'm telling you stuff you already know)

Finally, watch out when you modify the code that DW has produced, you will find that once you have changed it DW can't do a lot with it. Within the main part of your pages you can add bits more easily by keeping them within the &lt;? and ?&gt; php tags, then dw will just show them as php when you are in design view.

I that doesn't work post a few more lines of the code and I'll take a look and see what can be done <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Replied 12 May 2008 19:10:29
12 May 2008 19:10:29 Will S. replied:
Thanks Alan!

I'm one to say that using a WYSIWYG is probably a bad idea for coding but it helps speed up the process. Anyways... I figured out a different way of doing this. The purpose of my project was to create a simple registration form for VPN accounts. The policy states that the username and password for the VPN account has to be in fname.lname format. This meant that I had to enforce this via the registration form and inform the end-user, so to get around the issue I simply removed the Name (username) field from the registration from, set the database column to allow null for the Name (username).

Registration form: add a javascript to remove spaces from first and last name fields:

function NoSpc(obj){
obj.value=obj.value.replace(/^\s+|\s+$/g,'');
}

Activation page, added a simple query:

$query_changeusername = sprintf("SELECT * FROM users WHERE ID = %s", GetSQLValueString($colname_changeusername, "int");
$changeusername = mysql_query($query_changeusername, $webops) or die(mysql_error());
$row_changeusername = mysql_fetch_assoc($changeusername);
$totalRows_changeusername = mysql_num_rows($changeusername);

It uses the kt_login_id (session variable) to update the database column with fname.lname once the manager activates the account by clicking the activation link in the email. This is a little more secure because until the manager activates the account, the user VPN account is not active.

I'm not sure if this would have been the ideal way of doing it but it seems a little more secure for my purposes <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Replied 12 May 2008 19:45:08
12 May 2008 19:45:08 Alan C replied:
great to see that - I really like that Javascript in there to get rid of odd characters, so easy but it saves so much trouble later. I sort out the case too on mine so that names etc look better before they go into the tables. I like that activation stage too - it might slow things down a bit for the user but it adds security - someone said you can't be too rich, I would add careful with user input to that <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Reply to this topic