I'm having some trouble with my ColdFusion code,
I have a simple form, and all I want it to do is to add the values to the database. I keep getting the error:
"error code 206
[Macromedia][SQLServer JDBC Driver][SQLServer]Operand type clash: int is incompatible with text"
Here's my code:
<div class="form">
<form method="post" name="color">
ID:
<input type="text" name="id" id="id">
Color Name:
<input type="text" name="color" id="color">
Hex Value:
<input type="text" name="hex" id="hex">
<input type="submit" value="Submit">
</form>
</div>
<div>
<cfif structKeyExists(form, "color")>
<cfquery datasource="bentest" name="insertColor">
USE [benTest]
INSERT INTO color_codes
(id ,color, hexvalue)
VALUES
(#form.id#, '#form.color#', #form.hex#)
</cfquery>
<p>You've added a color to the database!</p>
</cfif>
</div>
And if I remove the single quotes from #form.color#, I get "Invalid column name '(what I entered)'."
If the hexvalue field in the database is a text field, e.g. nvarchar, varchar, text, then at a minimum you will need quotes around the variable... i.e.
<cfquery datasource="bentest" name="insertColor">
USE [benTest]
INSERT INTO color_codes (id ,color, hexvalue)
VALUES (#form.id#, '#form.color#', '#form.hex#')
</cfquery>
However I strongly suggest you also cfqueryparam them too, i.e.
<cfquery datasource="bentest" name="insertColor">
USE [benTest]
insert into
[color_codes] (
[Id],
[Color],
[HexValue]
)
values (
<cfqueryparam value="#Form.Id#" cfquerytype="cf_sql_integer">,
<cfqueryparam value="#Form.Color#" cfquerytype="cf_sql_varchar">,
<cfqueryparam value="#Form.Hex#" cfquerytype="cf_sql_varchar">
)
</cfquery>
You need to add quotes for #form.hex# because it is a string value, not integer:
INSERT INTO color_codes
(id ,color, hexvalue)
VALUES
(#form.id#, '#form.color#', '#form.hex#')
Actually, it looks like your id is a text field as well. Is this how it is set up in the database? You're not doing any verification that the value is numeric.... Often the ID is an auto-incrementing field, and not supplied by the user at all on insert.
Related
I have an HTML5 date input element like this:
<input type="date" />
if you choose a date in this input a string will be the value, for example:
"2018-12-31"
In my model I want the date to be presented as the following string:
"2018-12-31T00:00:00.000Z" and not the simplified string.
How do I make sure that the date in my model keeps the correct format? I tried using a computed but since I am in a loop this time I cannot use them.
{{eventDate.date}}
<b-form-input
v-bind:value="eventDate.date"
v-on:input="eventDate.date = $event.target.value"
v-bind:id="'event-day-date-' + index"
size="sm"
type="date"
placeholder="2018-12-31"
>
</b-form-input>
As you can see here the eventDate.date is a long string but the input needs the format YYYY-MM-DD. I need to convert it to and from this format some way.
You could use a filter:
filter: {
dateToString(date) {
return date.toString().substr(0,10)
}
}
and then update your template
:value="eventDate.date | dateToString"
This is what I ended up using:
<input
v-validate="'required'"
v-bind:name="'eventdate-' + index"
v-bind:value="eventDate.date | dateToString"
v-on:input="eventDate.date = $event.target.value + 'T00:00:00.000Z'"
v-bind:id="'event-day-date-' + index"
class="form-control form-control-sm"
type="date"
placeholder="2018-12-31"
/>
I am trying to follow a tutorial online and I have followed the steps exactly however i keep getting an error when trying to write to a database.
Here Is the code for a simple form
#{
var name = string.Empty;
var email = string.Empty;
var subject = string.Empty;
var message = string.Empty;
if (IsPost){
name = Request["txtName"];
email = Request["txtEmail"];
subject = Request["txtSubject"];
message = Request["txtMessage"];
var db = Database.Open("FormAndDataDB");
db.Execute("INSERT INTO ContactLog (Name, Email, Subject, Message, DateSent) " +
"VALUES (#0, #1, #2, #3, #4)", name, email, subject, message, DateTime.Now);
}
}
<doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form action="contact.cshtml" method="POST">
<p>
<label for="txtName">Name:</label><br />
<input type="text" name="txtName" id="txtName" value="#name"/>
</p>
<p>
<label for="txtEmail">Email:</label><br />
<input type="text" name="txtEmail" id="txtEmail" value="#email" />
</p>
<p>
<label for="txtSubject">Subject:</label><br />
<input type="text" name="txtSubject" id="txtSubject" value="#subject" />
</p>
<p>
<label for="txtMessage">Message:</label><br />
<textarea name="txtMessage" id="txtMessage" cols="40" rows="10" >#message</textarea>
</p>
<p>
<input type="submit" value="send" />
</p>
</form>
</body>
</html>
Here is the error i get in visual studio on attempt of execution of the SQL insert statement:
"An exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll but was not handled in user code"
This is the error text returned from SQL and displayed on the webpage:
"The column cannot contain null values. [ Column name = ID,Table name = ContactLog ]"
I have filled out the form completely
Your errors in the question notwithstanding, the problem seems to be that you've got a table (contactLog) with a column (id) that has the NOT NULL attribute attached to it. You are trying to insert a row without a value in said column, and that is causing this error.
To fix this either insert a value into the [ID] column or set the identity attribute to TRUE instead of FALSE on said column and allow it to autogenerate / autoincrement.
My assumption is that even when you fixed the syntax of the insert statement you still couldn't process the insert properly.
You have five columns, but only 3 values.
Your statement is
INSERT INTO ContactLog (Name, Email, Subject, Message, DateSent)
VALUES (#0, #1, #3)
What happened to #2 and #4?
Maybe you need
db.Execute("INSERT INTO ContactLog (Name, Email, Subject, Message, DateSent) "+
"VALUES (#0, #1, #2, #3, #4)",
name, email, subject, message, DateTime.Now);
I have a simple search page with this text input form
<form name="assetInput" action="assetResult.jsp" method="get">
<input type="text" name="assetNo" />
<input type="submit" value="Submit" />
</form>
which takes you to a results page that will search an Access database by the Asset Number you type in the search page. The column's data type is number.
This is the code to get the input from the text box, and my attempt to convert the String to an int.
<%
String assetNumber = request.getParameter("assetNo");
int assetNum = Integer.parseInt(assetNumber);
%>
My query:
rs = stmt.executeQuery( "SELECT * FROM [Inventory Tracking] WHERE (([Inventory Tracking].AssetNumber) = '"+assetNum+"')");
I'm able to search columns from the database whose data type is text, but I keep getting errors when trying to search a number column with a String.
Thanks in advance!
Numbers do not take a delimiter, only text fields.
rs = stmt.executeQuery( "SELECT * FROM [Inventory Tracking] WHERE [Inventory Tracking].AssetNumber = "+assetNum);
You could avoid a lot of problems with a parameter.
I'm creating a form elements template file in PHPTAL. I would like to be able to OPTIONALLY pass in an id attribute for a field...
So far the code looks like this:
<xml>
<tal:block metal:define-macro="text">
<label tal:condition="php: !isset(hideLabel) || isset(hideLabel) && !hideLabel">${field/label}</label>
<input name="${name}" type="text" value="${field/value}" />
<p tal:condition="exists:field/error">${field/error}</p>
</tal:block>
</xml>
This works as advertised. What I'd like to add is something, like
<input name="${name}" tal:attributes="id exists: id $id | $name" value="${field/value}" />
to allow me to optionally pass in an id from the METAL call...
Should I be doing it differently? I've tried using PHP: isset(id) ? $id : NULL and variations thereof, but just end up with an id="0" in the resultant HTML.
Any ideas?
In case anyone else needs it, one working answer is:
<xml>
<tal:block metal:define-macro="text">
<label tal:condition="not: exists:hideLabel">${field/label}</label>
<input name="${name}" tal:attributes="id id | nothing" type="text" value="${field/value}" />
<p tal:condition="exists:field/error">${field/error}</p>
</tal:block>
</xml>
Where passed in variables are id, name, an array named field, and hideLabel .
Note, that I've also managed to simplify the label test to something which I believe is more idiomatically TAL.
Set VAR at a DIV containing the soon to be used element:
div class="" tal:define="VAR context.property"
div class="" tal:attributes="class python:'grid_8 omega' if VAR else 'grid_8 alpha'"
in PHP:
<div id="contentCenter" tal:attributes="id
php:isset(variable)&&isset(variable.property)?'IDVALUE':NULL">
Using:
select name, id
from "TEST"
where id :2
AND name :1
order by id desc
I am getting ORA: 00904 "TEST"."NAME": invalid identifier error but the wierd part is that I have checked my test table and it does not have NAME field but it has name field, I have also checked all the references which is made from that table and all other constraints but still it gives me same error. I do not know why, is there a way where I can check all the columns of the database for NAME column name or any other debuggind approach recommended would be highly welcomed.
DESC TEST;
Name Null Type
id NOT NULL NUMBER(11)
name VARCHAR2(29)
2 rows selected
EDIT
DESC TEST
Name Null Type
------------------------------ -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ID NOT NULL NUMBER(11)
NAME VARCHAR2(29)
2 rows selected
Java Code
public String searchExecute(HttpServletRequest req, javax.servlet.ServletContext ctx, String nextPage){
// ESCA-JAVA0266:
System.out.println("This is Awesome");
// ESCA-JAVA0266:
System.out.println("id:"+req.getParameter("s_1985"));
// ESCA-JAVA0266:
System.out.println("name:"+req.getParameter("s_1984"));
boolean bDisplayAll = StringUtils.stringToBoolean(req.getParameter("display_all"));
if(bDisplayAll)
// ESCA-JAVA0034:
req.setAttribute("c_display_all", "Y");
req.setAttribute("c_search_submitted", "Y");
return nextPage;
}
JSP Code
<%# page import="att.leadx.dbutils.AppUtils" %>
<%# page import="java.util.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-
1">
</head>
<link rel=stylesheet type=text/css href="leadx.css">
<body bgcolor="#FFFFFF"><BR>
<form NAME="forma" ACTION="dispatcher" METHOD="post">
<INPUT TYPE="hidden" name="action" value="">
<input type=hidden name="c_master" value="TEST_SEARCH">
<%
request.setAttribute("c_form", "TEST_SEARCH");
request.setAttribute("c_top_title","PROFILE > TEST_SEARCH");
request.setAttribute("c_top_link_image","images/setup_sm.gif");
request.setAttribute("c_top_link_action","user.search.setup");
request.setAttribute("c_top_link_app_func","search_setup");
request.setAttribute("c_top_link_alt_display","Setup search criteria");
%>
<jsp:include page="j_custom_search.jsp" flush="true" />
<table width="94%" border="0" cellspacing="1" cellpadding="3" align=center>
<tr>
<td colspan=4 align=center>
<INPUT TYPE="submit" value="Search" class=prismsbutton onclick="document.forma.action.value ='cep.project.search.execute'">
</td>
<td colspan=4 align=center>
<INPUT TYPE="button" value="Cancel" class=prismsbutton onclick="window.history.back()">
</td>
</tr>
</table>
</form>
<form NAME="formd" ACTION="dispatcher" METHOD="post">
<input type="hidden" name="c_jsp" value="j_test_dynamic_search.jsp">
<%
request.setAttribute("c_master", "TEST_SEARCH");
request.setAttribute("c_html_form","formd");
request.setAttribute("c_list_id","1984");
request.setAttribute("c_search_form","TEST_SEARCH");
Object args[] = att.utils.DataStore.arg(att.leadx.dbutils.AppUtils.getLoggedInUser(request), att.utils.DataStore.TYPE_NUMERIC);
request.setAttribute("c_args", args);
if (att.utils.StringUtils.stringToBoolean((String)request.getAttribute("c_search_submitted"))){
%>
<jsp:include page="j_master_detail_dlist.jsp" flush="true" />
<%
}
%>
</form>
<%!
private void o(String s){
if (att.leadx.dbutils.AppUtils.inDebug())
System.out.println("[J_USER_SEARCH.JSP] " + s);
}
%>
SQL Statement
select name, id from TEST where name = :1 AND id = :2 order by id desc
Error Message
Aug 16, 2010 5:22:21 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.sql.SQLException: ORA-00936: missing expression
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1451)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:651)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2110)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2324)
at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:627)
at att.utils.DataStore.retrieve(DataStore.java:724)
at org.apache.jsp.j_005fmaster_005fdetail_005fdlist_jsp._jspService(j_005fmaster_005fdetail_005fdlist_jsp.java:566)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:659)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:565)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:493)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:965)
at org.apache.jsp.j_005ftest_005fdynamic_005fsearch_jsp._jspService(j_005ftest_005fdynamic_005fsearch_jsp.java:102)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:659)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:457)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:395)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:311)
at att.leadx.nav.Dispatcher.service(Dispatcher.java:113)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
Thanks
SELECT *
FROM ALL_TAB_COLS
WHERE UPPER(COLUMN_NAME) = 'NAME';
will show you all columns called NAME
EDIT:
Based on your comment, aren't you missing the operators in your WHERE clause? ie =
select name, id
from "TEST"
where id :2 -- Surely you mean: id = :2
AND name :1 -- Surely you mean: name = :2
order by id desc
EDIT 2:
Based on the SQL*Plus output, it looks like you've created the table with lower-case column names. Whilst this is possible and valid it's usually just hard work. I'd recreate the columns with upper case names. (as Alex said)
EDIT 3:
I think...
SELECT "id", "name"
FROM TEST
WHERE "id" = :1
AND "name" = :2
ORDER BY "id" desc;
should work
It's a good idea not to surround column and table names with double-quotation marks unless you are know what you are doing and confident you need that.
In Oracle, database object names (including table and columns) are not case-sensitive and assumed upper-case unless you include them into double-quotes.
E.g, if a table created as TEST, it can be referred to as test, Test or TesT or "TEST".
But if it is created as "Test", you will only be able to refer to it as "Test" (in double quotation marks). All the other ways will result in "invalid identifier" error.