How can I determine why my JSON object fails? - json

In the following code, I am trying to get the data using ajax but it fails and alerts the error message in the ajax call.
I need the data in the object to populate a form. It just alerts "Ooop there is something wrong" in the error of the ajax call.
Please find below my ajax call. As I said previously it alert the error message and since it is not successful, nothing to show in the developer tool on my browser for console.log()
dim rstRev, strRevSQL
dim intReviewStatus
dim intReviewID
intReviewID = sqlsafe2(request("review_id"),2)
Set rstRev = Server.CreateObject("ADODB.Recordset")
strRevSQL = "exec ppsp_reviewDetails '" & intReviewID & "'"
rstRev.open strRevSQL, db,adOpenForwardOnly,adLockReadOnly
if not rstRev.EOF then
intValueScore = cint(rstRev("value_score"))
intQualityScore = cint(rstRev("quality_score"))
intReview_ID = intReviewID
reviewID = rstRev("review_id")
reviewDate = rstRev("review_date")
reviewEmail =rstRev("email")
pf_id = rstRev("pf_id")
product = rstRev("product_name")
reviewTitle =rstRev("review_title")
linkText = rstRev("link_text")
TT = cint(rstRev("t_and_t"))
reviewStatus = cint(rstRev("active"))
reviewText = rstRev("review_text")
ppResponse = rstRev("pp_response")
strJSON = "{" & _
"""success"": true," & _
"""intValueScore"":""" & intValueScore & """," & _
"""intQualityScore"":""" & intQualityScore & """," & _
"""intReview_ID"":""" & intReview_ID & """," & _
"""reviewID"":""" & reviewID & """," & _
"""reviewDate"":""" & reviewDate & """," & _
"""reviewEmail"":""" & reviewEmail & """," & _
"""pf_id"":""" & pf_id & """," & _
"""product"":""" & product & """," & _
"""reviewTitle"":""" & reviewTitle & """," & _
"""linkText"":""" & linkText & """," & _
"""TT "":""" & TT & """," & _
"""reviewStatus"":""" & reviewStatus & """," & _
"""reviewText"":""" & reviewText & """," & _
"""ppResponse"":""" & ppResponse & """" & _
"}"
%>
<%
end if
rstRev.Close
set rstRev = nothing
Response.Write(strJSON)
%>```
```$('tbody tr td a').click(function(e){
e.preventDefault()
var x =$(this).prop("href")
var y = x.indexOf("=")+1
revID = x.substring(y)
//alert (x)
$.ajax({
type:"POST",
dataType:"json",
async: true,
url:"/web_utils/ppgf_utils/ajax/xt-review_details05122019.asp",
data:{
review_id:revID
},
success:function(data){
window.scrollTo(0, 0)
if(data.success ==true){
console.log(data.success)
}
},
error:function(){
alert("Ooop Something is wrong")
}
});```

Related

Input, Edit action in Form Input Data Access 2013

I am writing vba for my work at Banking to manage my data in Access 2013, but i have something wrong when i try to run my code.
File DB here
My code which i used to find out in internet is:
Private Sub cmdthem_Click()
If Me.TXTLCNO.Tag & "" = "" Then
CurrentDb.Execute "INSERT INTO db(NOLCTRANSACTION, LCTYPE, LCXKLCNKREF, BENAPPLICANT, AMOUNT, CONTRACTNO, INPUTTER, AUTHORIZER, DATE, STATUS, NOTE) " & _
" VALUES(" & Me.TXTLCNO & ",'" & Me.CBO1 & "','" & _
Me.TXTREF & "','" & Me.TXTBEN & "#,'" & Me.TXTAMOUNT & "',#" & _
Me.TXTCONTRACT & "','" & Me.CBO2 & "','" & Me.CBO3 & "#,'" & Me.TXTDATE & "',#" & _
Me.TXTSTATUS & "','" & Me.TXTNOTE & "')"
Else
'otherwise (Tag of txtID store the id of db to modified)
'CurrentDb.Execute "Update db " & _
" SET NOLCTRANSACTION=" & Me.TXTLCNO & _
", LCTYPE='" & Me.CBO1 & "'" & _
", LCXKLCNKREF='" & Me.TXTREF & "'" & _
", BENAPPICANT='" & Me.TXTBEN & "'" & _
", AMOUNT='" & Me.TXTAMOUNT & "'" & _
", CONTRACTNO='" & Me.TXTCONTRACT & "'" & _
", INPUTTER='" & Me.CBO2 & "'" & _
", AUTHORIZER='" & Me.CBO3 & "'" & _
", DATE='" & Me.TXTDATE & "'" & _
", STATUS='" & Me.TXTSTATUS & "'" & _
", NOTE='" & Me.TXTNOTE & "'" & _
" WHERE NOLCTRANSACTION=" & Me.NOLC.Tag
End If
'clear form
cmdclear_Click
'refresh data in list
db_subform.Form.Requery
End Sub
But when i try to run this command, it always errors statement INSERT INTO db
My table's name is db, it has all fields above
Can you find out my mistake please? Thank you, best regards

Run-time Error '3061' Too few parameters. Expected 8

I'm trying to create a vba code to append some data to a Table named T_Tickets
Below the code I'm using.
Function addticketScheduleChange()
Dim route As String
route = InputBox("Please enter the URL for the ticket:", "Schedule Review")
Set db = CurrentDb
Dim frm As Form
Set frm = Form_Frm_View_Team
sSQL = "Insert INTO T_Tickets ([CSA Login],[Team Manager],[Schedule Description],[WF Shift Pattern],[Mytime Schedule Description],[Shift Pattern Description],[Mytime Description Code],[Type of Ticket],[Resolved?],[Date Submited],[Ticket Link])" _
& "Select " _
& "frm.[CSA Login]" & ", " _
& "frm.[Team Manager]" & ", " _
& "frm.[Schedule Description]" & ", " _
& "frm.[CSSM SPD]" & ", " _
& "frm.[Mytime Descrription]" & ", " _
& "frm.[Shift Pattern Descr]" & ", " _
& "frm.[MytimeDescriptionCode]" & ", " _
& "'Schedule Change'" & ", " _
& False & ", " _
& "Now()" & ", " _
& "route"
db.Execute sSQL
MsgBox ("Record saved.")
End Function
Any help is appreciated.
Try this:
sSQL = "Insert INTO T_Tickets ([CSA Login],[Team Manager],[Schedule Description],[WF Shift Pattern],[Mytime Schedule Description],[Shift Pattern Description],[Mytime Description Code],[Type of Ticket],[Resolved?],[Date Submited],[Ticket Link]) " _
& "Values (" _
& "'" & frm.[CSA Login] & "'," _
& "'" & frm.[Team Manager] & "'," _
& "'" & frm.[Schedule Description] & "'," _
& "'" & frm.[CSSM SPD] & "'," _
& "'" & frm.[Mytime Descrription] & "'," _
& "'" & frm.[Shift Pattern Descr] & "'," _
& "'" & frm.[MytimeDescriptionCode] & "'," _
& "'Schedule Change'," _
& " False, " _
& " Now(), " _
& "'" & route & "')"

MS Access using UPDATE statement keeps entering new data

I'm using an UPDATE Statement but whenever I click the Edit button then Update, it's entering a new line but with the same data.
My code:
Private Sub cmdAdd_Click()
'when we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtNumber.Tag & "" = "" Then
'this is for insert new
'add data to table
CurrentDb.Execute "INSERT INTO tblcompany (companyname, companyaddress, contactnumber, contactperson, emailaddress, website, plantlocation, projectinfo, consultant) " & _
" VALUES('" & Me.txtCompanyName & "','" & _
Me.txtCompanyAddress & "','" & Me.txtContactNumber & "','" & _
Me.txtContactPerson & "','" & Me.txtEmailAddress & "','" & _
Me.txtWebsite & "','" & Me.txtPlantLocation & "','" & _
Me.txtProjectInfo & "','" & Me.txtConsultant & "')"
Else
'otherwise (tag of txtNumber store the number of company to be modified)
CurrentDb.Execute "UPDATE tblcompany " & _
" SET companyname='" & Me.txtCompanyName & "''" & _
", companyaddress='" & Me.txtCompanyAddress & "''" & _
", contactnumber='" & Me.txtContactNumber & "'" & _
", contactperson='" & Me.txtContactPerson & "''" & _
", emailaddress='" & Me.txtEmailAddress & "'" & _
", website='" & Me.txtWebsite & "'" & _
", plantlocation='" & Me.txtPlantLocation & "''" & _
", projectinfo='" & Me.txtProjectInfo & "''" & _
", consultant='" & Me.txtConsultant & "''" & _
" WHERE number=" & Me.txtNumber.Tag
End If
'clear form
cmdClear_Click
'refresh data in list on form
frmCompanySub.Form.Requery
End Sub
Isn't the Tag property empty by default? if you're saving a new record you will have to set a tag property equal to the number. So that when you come to update a record the Where number = & me.txt.number.tag is true. Otherwise all record tags of "" will equal "".
Also, tab in on your currentDb.execute line (after then).

What's causing my UPDATE statement not to work?

Good evening all,
I'm using the following as an attempt to update records in my MySQL database, but the records aren't being updated and I'm not catching any exceptions either. Your help would be kindly appreciated:
dbConn = New MySqlConnection("Server=" & FormLogin.ComboBoxServerIP.SelectedItem & ";Port=3306;Uid=trojan;Password=horse;Database=accounting")
Try
If dbConn.State = ConnectionState.Open Then
dbConn.Close()
Else
Try
dbConn.Open()
Dim dbAdapter As New MySqlDataAdapter("UPDATE customer " & _
"SET accountNumber= '" & TextBoxAccount.Text & "', nameLAST='" & TextBoxLastName.Text & "', nameFIRST='" & TextBoxFirstName.Text & "'" & _
"nameSALUTATION='" & ComboBoxSalutation.SelectedItem & "', nameCOMPANY='" & TextBoxCompanyName.Text & "', addressSTREET='" & TextBoxAddress1.Text & "'" & _
"addressSTREET1='" & TextBoxAddress2.Text & "', addressCITY='" & TextBoxCity.Text & "', addressSTATE='" & ComboBoxState.SelectedItem & "'" & _
"addressZIPCODE='" & MaskedTextBoxZip.Text & "', phone='" & MaskedTextBoxPhone.Text & "', fax='" & MaskedTextBoxFax.Text & "', email='" & TextBoxEmail.Text & "'" & _
"WHERE accountNumber='" & TextBoxAccount.Text & "';", dbConn)
Catch ex As Exception
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
End Try
MessageBox.Show("Customer account SUCCESSFULLY updated!")
Call lockForm()
End If
Catch ex As Exception
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
End Try
Call lockForm()
dbConn.Close()
Use MySQLCommand instead of MySQLDataAdapter. You are defeating the purpose of using ADONet because still your code is vulnerable with sql injection. Make it parameterized. Below is a modified code from your code. It uses Using-End Using for proper handling of object disposal.
Dim ConnectionString As String ="Server=" & FormLogin.ComboBoxServerIP.SelectedItem & ";Port=3306;Uid=trojan;Password=horse;Database=accounting"
Dim iQuery As String = "UPDATE customer " & _
"SET accountNumber = #accountNumber, nameLAST = #nameLAST, nameFIRST = #nameFIRST, " & _
" nameSALUTATION = #nameSALUTATION, nameCOMPANY = #nameCOMPANY, addressSTREET = #addressSTREET, " & _
" addressSTREET1 = #addressSTREET1, addressCITY = #addressCITY, addressSTATE = #addressSTATE, " & _
" addressZIPCODE = #addressZIPCODE, phone = #phone, fax = #fax, email = #email " & _
"WHERE accountNumber = #accountNumber"
Using dbConn As New MySqlConnection(ConnectionString)
Using dbComm As New MySQLCommand()
With dbComm
.Connection = dbConn
.CommandType = CommandType.Text
.CommandText = iQuery
.Parameters.AddWithValue("#accountNumber", TextBoxAccount.Text )
.Parameters.AddWithValue("#nameLAST", TextBoxLastName.Text)
.Parameters.AddWithValue("#nameFIRST", TextBoxFirstName.Text)
.Parameters.AddWithValue("#nameSALUTATION", ComboBoxSalutation.SelectedItem)
.Parameters.AddWithValue("#nameCOMPANY", TextBoxCompanyName.Text)
.Parameters.AddWithValue("#addressSTREET", TextBoxAddress1.Text)
.Parameters.AddWithValue("#addressSTREET1", TextBoxAddress2.Text)
.Parameters.AddWithValue("#addressCITY", TextBoxCity.Text)
.Parameters.AddWithValue("#addressSTATE", ComboBoxState.SelectedItem)
.Parameters.AddWithValue("#addressZIPCODE", MaskedTextBoxZip.Text)
.Parameters.AddWithValue("#phone", MaskedTextBoxPhone.Text)
.Parameters.AddWithValue("#fax", MaskedTextBoxFax.Text)
.Parameters.AddWithValue("#email", TextBoxEmail.Text)
End With
Try
dbConn.Open
dbComm.ExecuteNonQuery()
MessageBox.Show("Customer account SUCCESSFULLY updated!")
Call lockForm()
Catch( ex as MySQLException)
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
Finally
dbConn.Close()
End Try
End Using
End Using
In this case, I would use ExecuteNonQuery as you can't use a MySQLDataAdapter the way you are trying to use it. Also please use paramters as what you are doing opens you up to SQL injection attacks. And finally you don't need to update accountNumber because you are using that to find the row which you want to update!

VB+Crystal report

I wrote this code but I got "Run time error '91':"
Private Sub Command1_Click()
Set rs = New ADODB.Recordset
openConnection
If Me.cmbMonth = "" And Me.cmbYear = "" Then
MsgBox "Please select MONTH and YEAR"
Exit Sub
End If
With crystalrpt
.ReportFileName = App.Path & "\Report\VariableReport.rpt" <-- ERROR IS HERE
.SelectionFormula = "{SW.dtaMonth}='" & cmbMonth.Text & "' and {SW.dtaYear}=" & dtaYear.Text & "" & _
" and {SFW.dtaMonth}='" & cmbMonth.Text & "' and {SFW.dtaYear}=" & dtaYear.Text & "" & _
" and {OT.dtaMonth}='" & cmbMonth.Text & "' and {OT.dtaYear}=" & dtaYear.Text & "" & _
" and {CL.dtaMonth}='" & cmbMonth.Text & "' and {CL.dtaYear}=" & dtaYear.Text & "" & _
" and {RM.dtaMonth}='" & cmbMonth.Text & "' and {RM.dtaYear}=" & dtaYear.Text & "" & _
" and {EL.dtaMonth}='" & cmbMonth.Text & "' and {EL.dtaYear}=" & dtaYear.Text & "" & _
" and {TRANS.dtaMonth}='" & cmbMonth.Text & "' and {TRANS.dtaYear}=" & dtaYear.Text & "" & _
" and {WD.dtaMonth}='" & cmbMonth.Text & "' and {WD.dtaYear}=" & dtaYear.Text & "" & _
" and {MP.dtaMonth}='" & cmbMonth.Text & "' and {MP.dtaYear}=" & dtaYear.Text & "" & _
" and {NONSTOCK.dtaMonth}='" & cmbMonth.Text & "' and {NONSTOCK.dtaYear}=" & dtaYear.Text & "" & _
" and {PACK.dtaMonth}='" & cmbMonth.Text & "' and {PACK.dtaYear}=" & dtaYear.Text & ""
.WindowTitle = "Report"
.Action = 1 'Will Show The Report
End With
End Sub
It's possible that you are trying to create an instance of a class (an object) from a class that is present on the machines you tested it on, but not on the machine it's been deployed to..... for example, I happen to know that I can make a VB program utilize a class for Nero Burning Rom.... I can make a nero object, and use it's methods and properties...... but that will only work on machines that have the Nero libraries installed. If it's not installed, when you try to make the object (either through early or late bindings with new or createobject), the variable that SHOULD refer to the object is still set to Nothing, because the library failed to create an instance of the requested class.....