473,785 Members | 2,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

empty input field submits and enters 0 in sql table??

120 New Member
I have a CMS which displays some flight routes, alongside prices, dates which is using asp and sql server 05.

works well - i.e an update on the CMS page populates the sql table and then the asp page reflects this update too.

only problem is if the price input field is left empty once submitted 0 in entered in to the sql table?? there's no js validation on the cms and the price column is set to integer and it's default value is set to NULL.

edit.asp code
Expand|Select|Wrap|Line Numbers
  1. <%
  2. 'declare you variables
  3. Dim SQL, connection, recordset
  4. Dim sConnString, ID 'receive the id of the record passed through querystring
  5. ID = Trim(Request("ID"))
  6. 'ID=request.querystring("ID")
  7. 'ID=request.form("ID") 'receive the hidden form ID
  8.  
  9. 'Declare the SQL statement that will query the database
  10. SQL="SELECT * FROM UK_Specials WHERE ID='" & ID & "' "
  11.  
  12. 'Create an ADO connection and recordset object
  13. Set Connection = Server.CreateObject("ADODB.Connection")
  14. Set Recordset = Server.CreateObject("ADODB.Recordset")
  15.  
  16. 'define the connection string, specify database
  17. 'driver and the location of database
  18. sConnString="Provider=SQLOLEDB;Data Source=********" & _
  19. "Initial Catalog=MYDBNAME;User ID=****;Password=*************"
  20.  
  21. 'Open the connection to our database
  22. Connection.Open(sConnString)
  23.  
  24. 'Open the recordset object, execute the SQL statement
  25. 'and return the record with the id that was sent
  26. recordset.Open SQL,connection
  27. %>
  28.  
  29. <div align="center" style="width:360px; padding:10px">
  30.  
  31. <form name="UKSpecialsUpdate" id="UKSpecialsUpdate" method="post" onSubmit="return validate();" action="update.asp" />
  32. <input type="hidden" name="ID" id="ID" value="<%= recordset("ID")%>" />
  33. <table align="center" width="100%" cellpadding="0" cellspacing="0">
  34.   <tr>
  35.     <td style="font-weight:bold; color:#01207B"><%= recordset("Flight_Route")%></td>
  36.     <td style="font-weight:bold; text-align:right"><a style="text-align:right" href="javascript: self.close ()">Close Window</a></td>
  37.   </tr>
  38. </table>
  39.  
  40. <table align="center" width="100%" cellpadding="0" cellspacing="0" style="margin:20px 0 0 0">
  41.   <tr>
  42.     <td colspan="2" style="font-weight:bold; font-size:15px; padding:0 0 5px 0; text-align:right">Price</td>
  43.     <td style="font-weight:bold; font-size:15px; padding:0 0 5px 0; text-align:right">Month</td>
  44.     <td style="font-weight:bold; font-size:15px; padding:0 0 5px 0; text-align:right">Date/s</td>
  45.   </tr>
  46.   <tr>
  47.     <td align="right" style="padding:0 5px 5px 0">&pound;</td>
  48.     <td align="right" style="padding:0 0 5px 0">
  49.     <input name="PriceBand1" type="text" id="PriceBand1" size="4" maxlength="4" value="<%= recordset("Price_Band_1")%>"></td>
  50.     <td align="right" style="padding:0 0 5px 5px">
  51.     <input name="MonthBand1" type="text" id="MonthBand1" size="4" maxlength="4" value="<%= recordset("Month_Band_1")%>"></td>
  52.     <td align="right" style="padding:0 0 5px 0">
  53.     <input name="DateBand1" type="text" id="DateBand1" size="30" maxlength="100" value="<%= recordset("Date_Band_1")%>"></td>
  54.   </tr>
  55.   <tr>
  56.     <td align="right" style="padding:0 5px 5px 0">&pound;</td>
  57.     <td align="right" style="padding:0 0 5px 0">
  58.     <input name="PriceBand2" type="text" id="PriceBand2" size="4" maxlength="4" value="<%= recordset("Price_Band_2")%>"></td>
  59.     <td align="right" style="padding:0 0 5px 5px">
  60.     <input name="MonthBand2" type="text" id="MonthBand2" size="4" maxlength="4" value="<%= recordset("Month_Band_2")%>"></td>
  61.     <td align="right" style="padding:0 0 5px 0">
  62.     <input name="DateBand2" type="text" id="DateBand2" size="30" maxlength="100" value="<%= recordset("Date_Band_2")%>"></td>
  63.   </tr>
  64.   <tr>
  65.     <td align="right" style="padding:0 5px 5px 0">&pound;</td>
  66.     <td align="right" style="padding:0 0 5px 0">
  67.     <input name="PriceBand3" type="text" id="PriceBand3" size="4" maxlength="4" value="<%= recordset("Price_Band_3")%>"></td>
  68.     <td align="right" style="padding:0 0 5px 5px">
  69.     <input name="MonthBand3" type="text" id="MonthBand3" size="4" maxlength="4" value="<%= recordset("Month_Band_3")%>"></td>
  70.     <td align="right" style="padding:0 0 5px 0">
  71.     <input name="DateBand3" type="text" id="DateBand3" size="30" maxlength="100" value="<%= recordset("Date_Band_3")%>"></td>
  72.   </tr>
  73.   <tr>
  74.     <td align="right" style="padding:0 5px 5px 0">&pound;</td>
  75.     <td align="right" style="padding:0 0 5px 0">
  76.     <input name="PriceBand4" type="text" id="PriceBand4" size="4" maxlength="4" value="<%= recordset("Price_Band_4")%>"></td>
  77.     <td align="right" style="padding:0 0 5px 5px">
  78.     <input name="MonthBand4" type="text" id="MonthBand4" size="4" maxlength="4" value="<%= recordset("Month_Band_4")%>"></td>
  79.     <td align="right" style="padding:0 0 5px 0">
  80.     <input name="DateBand4" type="text" id="DateBand4" size="30" maxlength="100" value="<%= recordset("Date_Band_4")%>"></td>
  81.   </tr>
  82.   <tr>
  83.     <td align="right" style="padding:0 5px 5px 0">&pound;</td>
  84.     <td align="right" style="padding:0 0 5px 0">
  85.     <input name="PriceBand5" type="text" id="PriceBand5" size="4" maxlength="4" value="<%= recordset("Price_Band_5")%>"></td>
  86.     <td align="right" style="padding:0 0 5px 5px">
  87.     <input name="MonthBand5" type="text" id="MonthBand5" size="4" maxlength="4" value="<%= recordset("Month_Band_5")%>"></td>
  88.     <td align="right" style="padding:0 0 5px 0">
  89.     <input name="DateBand5" type="text" id="DateBand5" size="30" maxlength="100" value="<%= recordset("Date_Band_5")%>"></td>
  90.   </tr>
  91.   <tr>
  92.     <td colspan="4" style="padding:20px 0 0 0" align="right"><input class="button" type="submit" value="UPDATE" /></td>
  93.   </tr>
  94. </table>
  95. </form>
  96.  
  97. </div>
  98.  
  99. <%
  100. 'close the connection and recordset objects
  101. recordset.Close
  102. Set recordset=Nothing
  103. connection.Close
  104. Set connection=Nothing
  105. %>
  106.  
update.asp code
Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3. 'declare your variables
  4. Dim connection, sSQL, sConnString, ID
  5. Price_Band_1=Request.Form("PriceBand1")
  6. Month_Band_1=Request.Form("MonthBand1")
  7. Date_Band_1=Request.Form("DateBand1")
  8. Price_Band_2=Request.Form("PriceBand2")
  9. Month_Band_2=Request.Form("MonthBand2")
  10. Date_Band_2=Request.Form("DateBand2")
  11. Price_Band_3=Request.Form("PriceBand3")
  12. Month_Band_3=Request.Form("MonthBand3")
  13. Date_Band_3=Request.Form("DateBand3")
  14. Price_Band_4=Request.Form("PriceBand4")
  15. Month_Band_4=Request.Form("MonthBand4")
  16. Date_Band_4=Request.Form("DateBand4")
  17. Price_Band_5=Request.Form("PriceBand5")
  18. Month_Band_5=Request.Form("MonthBand5")
  19. Date_Band_5=Request.Form("DateBand5")
  20. ID=request.form("ID") 'receive the hidden form ID
  21.  
  22. 'declare SQL statement that will query the database
  23. sSQL="UPDATE UK_Specials SET " & _
  24. "Price_Band_1='" & Price_Band_1 & "', Month_Band_1='" & Month_Band_1 & "', Date_Band_1='" & Date_Band_1 & "'," & _
  25. "Price_Band_2='" & Price_Band_2 & "', Month_Band_2='" & Month_Band_2 & "', Date_Band_2='" & Date_Band_2 & "'," & _ 
  26. "Price_Band_3='" & Price_Band_3 & "', Month_Band_3='" & Month_Band_3 & "', Date_Band_3='" & Date_Band_3 & "'," & _ 
  27. "Price_Band_4='" & Price_Band_4 & "', Month_Band_4='" & Month_Band_4 & "', Date_Band_4='" & Date_Band_4 & "'," & _ 
  28. "Price_Band_5='" & Price_Band_5 & "', Month_Band_5='" & Month_Band_5 & "', Date_Band_5='" & Date_Band_5 & "'  WHERE ID='" & ID & "' "
  29.  
  30. 'create an ADO connection object
  31. Set connection = Server.CreateObject("ADODB.connection")
  32.  
  33. 'define the connection string, specify database
  34. 'driver and the location of database
  35. sConnString="Provider=SQLOLEDB;Data Source=************;" & _
  36. "Initial Catalog=MYDBNAME;User ID=**********;Password=**********"
  37.  
  38. 'Open the connection to the database
  39. Connection.Open sConnString
  40.  
  41. 'Execute the SQL statement
  42. Connection.Execute sSQL
  43.  
  44. 'Now close the connection object
  45. connection.Close
  46. Set connection = Nothing
  47.  
  48. Response.write "<p style=""padding:100px 0 0 0; text-align:center; font-weight:bold; font-size:18px"">" & _
  49. "Prices / Dates Updated!</p>"
  50.  
  51. %>
  52.  
thanks in advance
Omar.
Sep 29 '10 #1
5 2764
Nicodemas
164 Recognized Expert New Member
If you do a
Expand|Select|Wrap|Line Numbers
  1. Response.Write Typename(Price_Band_1)
on line 6 of update.asp, what does it say?

Also, I noted in your SQL string that you are saving this information as a string. I know this because you have wrapped the value from the form in apostrophes. Is this the way your database is set up - are those fields CHAR/VARCHAR/TEXT-based data type fields? Check your database setup and let me know.

This last could definitely be part of the problem. I do not see why you would store the number as a string value if it is meant to reflect a price.
Sep 29 '10 #2
omar999
120 New Member
hi nicodemas

Response.Write Typename(Price_ Band_1) returns Empty on the update.asp page... im still fairly weak with my asp so I have no idea what this means?

the ID, Price_Band fields are set as type integer in the table whereas the date, month and other fields are all set as varchar(50).. is this wrong?

shall I remove all apostrophe's from my Update statement to fix??

please advise
Sep 30 '10 #3
Nicodemas
164 Recognized Expert New Member
Empty basically means it has no value assigned to it. The question to ask yourself is, why is PriceBrand1 Empty? Also, according to standard SQL, integer data type fields' values should not be enclosed in apostrophes. So, yes, remove the apostrophes from around your integer fields' values.
Sep 30 '10 #4
omar999
120 New Member
some priceband fields are empty and purposely contain a NULL value in the table. This is a requirement where there are no prices to be inserted in some priceband fields. And I cant enter 0 as I also perform a minimum price calculated based on all records to therefore if there is no price NULL is what I enter as this works for me.

I will try to remove the apostrophes from around my integer field values and will report back progress..
Oct 1 '10 #5
omar999
120 New Member
UPDATE: i've taken your advice and by removing the apostrophe's from around my integer field values - only problem now is when I leave the field Price_Band_1 empty I get the following error

Microsoft OLE DB Provider for SQL Server error '80040e14'
Incorrect syntax near ','.
/prices-databasetest/update.asp, line 71
Expand|Select|Wrap|Line Numbers
  1. 'declare SQL statement that will query the database
  2. sSQL="UPDATE UK_SpecialsTEST SET " & _
  3. "Price_Band_1=" & Price_Band_1 & ", Month_Band_1='" & Month_Band_1 & "', Date_Band_1='" & Date_Band_1 & "'," & _
  4. "Price_Band_2=" & Price_Band_2 & ", Month_Band_2='" & Month_Band_2 & "', Date_Band_2='" & Date_Band_2 & "'," & _ 
  5. "Price_Band_3=" & Price_Band_3 & ", Month_Band_3='" & Month_Band_3 & "', Date_Band_3='" & Date_Band_3 & "'," & _ 
  6. "Price_Band_4=" & Price_Band_4 & ", Month_Band_4='" & Month_Band_4 & "', Date_Band_4='" & Date_Band_4 & "'," & _ 
  7. "Price_Band_5=" & Price_Band_5 & ", Month_Band_5='" & Month_Band_5 & "', Date_Band_5='" & Date_Band_5 & "'  WHERE ID='" & ID & "' "
  8.  
please advise as I'm not sure where the problem is
Oct 1 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
4848
by: Ben | last post by:
Hi all, i have file input field in a form like this: <input name="isbn" type="text" size="25" value="<?php echo $_POST ?>" /> <input name="image" type="file" size="25" value="<?php echo $_FILES ?>" /> when i press "submit" button, the same page gets loaded... if my $_POST is empty, i want to have the file path on "file input
3
5178
by: KathyB | last post by:
Hi, I'm trying to find a way to validate input text boxes where I don't know the names until the page is rendered. I've got 2 validate functions that fire with the onsubmit button of a "mini" form within the html document. When the Finish button is clicked, I need to check for any empty input boxes before loading the next aspx page...but it could be no boxes or five boxes, etc.? I've included my html output...if you have any ideas,...
13
4810
by: Eddie | last post by:
I need to validate a text input field. I just want to say if user enters 93101 or 93102 or 93103 or 93105 or 93106 or 93107 or 93108 or 93109 or 93110 or 93111 or 93116 or 93117 or 93118 or 93120 or 93121 or 93130 or 93140 or 93150 or 93160 or 93190 or 93199 or 93199 or 93401 or 93402 or 93403 or 93405 or 93406 or 93407 or 93408 or 93409 or 93410 or 93412
7
6769
by: JW | last post by:
hello everybody I've got the following problem. I'm writing a form and I'm using javascript to validate fields (i.e. numeric, not blank). When my scripts detects an error I want it to put the cursor in the corresponding field. I've tried the focus option, but that doesn't seem to work. This is the code I'm using: if (TestOk=="N") { alert('Veld mag niet leeg zijn');
5
2340
by: Clive Backham | last post by:
I'm having trouble with Instant Payment Notification on PayPal. One of the forms that they generate, which invokes one of my scripts, has a submit button with a blank name. The HTML fragment is this: <input type="submit" name="" value="Continue"> This causes the FORMDATA that is sent to my script to start like this: =Continue&nextparam=value&....
7
3283
by: Amy | last post by:
I'm trying to add an autoincrementing id to a table based on an existing field Name, but Name has duplicated records. How can I do that in ACCESS? Thanks. Amy
13
14401
by: Lee | last post by:
I have this function that doesn't work. I pass it the td element and an id, and it makes an input field inside the td. That part workds. What doesn't work is that I want to add an "onkeyup" on the input field. Any help? Please??? I don't get any error on my javascript console in firefox, and I am not seeing any errors in IE. // makes an input field that submits itself using setCalendarValue() when it's blurred (it will be blurred if...
14
1933
by: rbowman40 | last post by:
I am trying to design a form in which a category (field in a table) is selected from a combo box, then a value for that category is entered in a form field. I want that value to be placed in the field selected from the drop down list in the combo box. It would be like what happens when a bookkeeper selects an account field from a list and then enters a value for it. The value is then appended to the specified account field. I think this should...
3
4825
by: cbradio | last post by:
Hi, I am having trouble developing a form in a restricted environment. My sample code is found below my message (sorry I don't have a URL). Basically, without a doctype, the form displays properly with 3px padding around each form field, and no overlap. But the doctype changes the box model, I am told, and so the padding is added to the 100% width, leading to overlap and poor presentation. Unfortunately, I'm forced to use the doctype due to...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9954
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.