grab first 4 characters of string

Hi.  Ok, so I have displayed:

[Checkbox] Team 1.jpg (id#: 1)
[Checkbox] Individual 1.jpg (id#: 2)
[Checkbox] Action 1.jpg (id#: 3)

The user chooses 2 of the following 3 selections and clicks Next to go to the next page.  What gets passed to the next page is the id#.  BUT I want him to choose only the 2 files which start with "team" and "indi".  If they don't choose those options, it goes back with an error.  So let's say he chooses id #1 and id #3, what would get passed to the next page is 1,3.  I figured that I would then query for the name of the image, then grab the first 4 characters of the name.  If the result is not "team" or "indi", then throw back the error.  Not sure how to do this though.  Any ideas?
COwebmasterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Renante EnteraSenior PHP DeveloperCommented:
Hi COwebmaster!

Assuming that your database is MSSQL.  So, I think this is what you are looking for :
--------------
NEXT PAGE
--------------
<cfquery name="qGetRecord" datasource="#REQUEST.Datasource#">
  SELECT imageId, imageName
  FROM tblImage
  WHERE imageId IN ('#FORM.checkbox#')
  AND
  (
    LEFT(imageName, 4) = 'team' OR LEFT(imageName, 4) = 'indi'
  )
</cfquery>

<cfif qGetRecord.recordcount LT ListLen(Form.checkbox)>
  <cfoutput>
    <b>ERROR FOUND</b><br>
    Be sure that the file you have selected starts with 'team' or 'indi'<br>
    <input type="button" name="backButton" value="Back" onclick="history.back()">
  </cfoutput>
</cfif>

*Note : On the query, the LEFT() function is a database function not coldfusion.  Then for another workaround, you can also use any of these :
  a.  SUBSTRING(imageName, 1, 4)
  b.  CAST(imagename as varchar(4))

I hope that this helps you.  Just try it.


Goodluck!
eNTRANCE2002 :-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
COwebmasterAuthor Commented:
Hello eNTRANCE2002!  Let me check it out..
COwebmasterAuthor Commented:
I'm getting an error saying "Element CHECKBOX is undefined in FORM"
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

COwebmasterAuthor Commented:
Ok, I realized that I wasn't calling out the name of the checkbox.  Anyway, now I have another error:

[Macromedia][SQLServer JDBC Driver][SQLServer]Syntax error converting the varchar value &apos;1855,1856&apos; to a column of data type int.

Renante EnteraSenior PHP DeveloperCommented:
Hmmm... :-?

Maybe, this part has the problem :
  WHERE imageId IN ('#FORM.checkbox#')

Try to change it with this :
  <!--- Just remove single quote --->
  WHERE imageId IN (#FORM.checkbox#)

I hope that this makes sense.


Regards!
eNTRANCE2002 :-)
COwebmasterAuthor Commented:
Worked, thanks!
COwebmasterAuthor Commented:
Final:


<cfquery name="qGetRecord" datasource="#REQUEST.Datasource#">
  SELECT imageId, imageName
  FROM tblImage
  WHERE imageId IN (#checkbox#)
  AND
  (
    LEFT(imageName, 4) = 'team' OR LEFT(imageName, 4) = 'indi'
  )
</cfquery>

<cfif qGetRecord.recordcount LT ListLen(checkbox)>
  <cfoutput>
    <b>ERROR FOUND</b><br>
    Be sure that the file you have selected starts with 'team' or 'indi'<br>
    <input type="button" name="backButton" value="Back" onclick="history.back()">
  </cfoutput>
</cfif>
Renante EnteraSenior PHP DeveloperCommented:
Hi COwebmaster!

I'm glad that I have helped you.  Hope to help you again.

BTW, thanks for the points and the grade.


Best regards!
eNTRANCE2002 :-0
COwebmasterAuthor Commented:
Thanks again entrance2002!  I just posted another cfm question.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.