Results 1 to 3 of 3

Thread: TRIM/MID

  1. #1
    Join Date
    Dec 1969

    Default TRIM/MID

    a serious issue here, been bothering me for a while. some have tried to help, but failed. Hopefully the third time will be a charm. I have a form that requests firstname and lastname among many other fields and it submits to a DB. I would like to take the first letter of first name and first 7 letters of last name and insert them into DB as a username. This is the code i have been using:<BR><BR>&#039this is declaring the username<BR><BR>&#060;%<BR>If Not IsNull(Request("FirstName")) Then <BR>strFirstName = Cstr(Request("FirstName"))<BR>End If<BR><BR>If Not IsNull(Request("LastName")) Then <BR>strlastName = Cstr(Request("LastName"))<BR>End if<BR><BR>strUserName = Mid(strFirstName,1,1)<BR>strUserName = strUsername & Mid(strLastName,1,7)<BR>%&#062;<BR><BR>&#039this is requesting the recordset<BR><BR>&#060;%<BR><BR>saveform = false<BR>&#039 simple way to see if we are coming in for the first time.<BR>&#039 since name is a required field, if it is not empty then<BR>&#039 we need to process the form.<BR>if (request("firstname") &#060;&#062; "") then<BR>&#039 saving the data to our subscribers table<BR> sql= "select * from subscribers"<BR>&#039 create and open a connection to our database<BR> set conntemp = server.createobject("adodb.connection")<BR> cnpath="dbq=" & server.mappath("grid.mdb")<BR> "driver={microsoft access driver (*.mdb)}; " & cnpath<BR>&#039 create a command set<BR> set cmdtemp = server.createobject("adodb.command")<BR> cmdtemp.commandtext = sql<BR> cmdtemp.commandtype = 1<BR> set cmdtemp.activeconnection = conntemp<BR>&#039 create a record set<BR> set datacommand1 = server.createobject("adodb.recordset")<BR> set datacommand1.activeconnection = conntemp<BR> cmdtemp, , 1, 3<BR>&#039 add a new record<BR> datacommand1.addnew<BR>&#039 fill in the fields.<BR>&#039 no error checking, all strings of 255 characters.<BR> datacommand1("firstname") = request("firstname")<BR> datacommand1("lastname") = request("lastname")<BR> datacommand1("address") = request("address")<BR> datacommand1("city") = request("city")<BR> datacommand1("state") = request("state")<BR> datacommand1("zip") = request("zip")<BR> datacommand1("email") = request("email")<BR> datacommand1("cctype") = request("cctype")<BR> datacommand1("ccnumber") = request("ccnumber")<BR> datacommand1("expiration") = request("expiration")<BR> datacommand1("hear") = request("hear")<BR> datacommand1("payment") = request("payment")<BR> datacommand1("username") = request("username")<BR> datacommand1("password") = request("password")<BR> datacommand1("date") = request("date")<BR> datacommand1.update<BR> datacommand1.close<BR><BR> conntemp.close<BR><BR>&#039 indicate we just saved a form<BR> saveform = true<BR>end if<BR>%&#062;<BR><BR>&#039this is the form part that should be used to write to the DB<BR><BR>&#060;input type="hidden" name="Username" value="&#060;%response.write(strUserName)%&#062;"& #062;<BR><BR>There is more code, however i did not think it was prevelant, so I only wrote what i thought i would need to be helpful.<BR>Now, i have been told that this should work, and in fact, if i use the response.write anywhere else on the page, it writes out what i want. For some reason (this is the heart of the problem), it will not write to the DB.<BR><BR>Very confused and need some help, all would be appreciated<BR><BR>Thanks<BR><BR>please feel free to email me at if you need any thing else from me as far as code or whatever.<BR>

  2. #2
    Sathiya Guest

    Default RE: TRIM/MID

    Change the column name DATE to something else its a reserved word.i think because of that only you cant write to DB.<BR><BR>firstletter --&#062; left(Trim(string),1)<BR>7 letter ---&#062; left(trim(string),7)

  3. #3
    Ian S Guest

    Default RE: TRIM/MID

    All I can do is point you down the right path.<BR><BR><BR>Try to break your code up into seperate statements<BR>to see what part of the code is causing the problem.<BR>You mentioned previously that you could write the username <BR>variable to the screen and it was correct but it wouldn&#039t<BR>save it to the Database. Logically this would point to a problem<BR>with the code related to the DB.<BR><BR>Does it add a new record?<BR>If you hardcode the value of &#039username&#039 does it show up in<BR>the Database?<BR>Does every other variable get entered?<BR>Try turning on OPTION EXPLICIT to debug.<BR><BR>Try to debug it by focusing on the DB part of<BR>the code. Simplify all the code into seperate peices, make sure<BR>they work, then combine.<BR><BR><BR>Ian S

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts