|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Inserting data int MySQL
I have a MySQL datasource configured in Coldfusion and data can be added to the database.
I have parsed several websites for job data and stored the data into several lists. The data in the lists takes the form of: Retail/Membership Assistant (title) £10,000 - £11,500 pa (salary) RSPB, Ribble Discovery Centre, Lancashire (location) Full time Established (hours) 30 March 2005 (app date) 6 April 2005 (iterview date) I try to add this data to my database: <cfloop from="1" to="#listLen(idList)#" index="j"> <cfquery name="insJobRecord" datasource="project"> insert into job (ref, Title, Salary) values (<cfqueryparam value="#listGetAt(idList, j)#" cfsqltype="CF_SQL_VARCHAR">, <cfqueryparam value="#listGetAt(TitleList, j)#" cfsqltype="CF_SQL_VARCHAR">, <cfqueryparam value="#listGetAt(SalaryList, j)#" cfsqltype="CF_SQL_VARCHAR">) </cfquery> </cfloop> However I get the following errror: Invalid list index 2. In function ListGetAt(list, index [, delimiters]), the value of index, 2, is not a valid as the first argument (this list has 1 elements). Valid indexes are in the range 1 through the number of elements in the list. The error occurred in C:\CFusionMX\wwwroot\Project\1.cfm: line 97 95 : values 96 : (<cfqueryparam value="#listGetAt(idList, j)#" cfsqltype="CF_SQL_VARCHAR">, 97 : <cfqueryparam value="#listGetAt(TitleList, j)#" cfsqltype="CF_SQL_VARCHAR">, 98 : <cfqueryparam value="#listGetAt(SalaryList, j)#" cfsqltype="CF_SQL_FLOAT">) 99 : All my datatypes in my database are the same as in my code. I can add the idlist values into the database but not the titlelist values. What am I doing wrong? Thanks in advance |
|
#2
|
|||
|
|||
|
The problem is that the titleList list does not have the same number of elements that the idList does, so on the second iteration of the loop you're getting an error because there is no second list element in the titleList.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
Thanks Kiteless, got another error that I dont really understant:
[Macromedia][SequeLink JDBC Driver][ODBC Socket][MySQL][ODBC 3.51 Driver][mysqld-4.0.21-nt]Column count doesn't match value count at row 1 The error occurred in C:\CFusionMX\wwwroot\Project\1.cfm: line 73 71 : (<cfqueryparam value="#Links[i]#" cfsqltype="CF_SQL_VARCHAR">, 72 : <cfqueryparam value="#thisJD#" cfsqltype="CF_SQL_LONGTEXT"> 73 : <cfqueryparam value="#thisTitle#" cfsqltype="CF_SQL_VARCHAR">) Again the datatype in the database and the code match, what does that mean? Thanks |
|
#5
|
|||
|
|||
|
thank you
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Inserting data int MySQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|