0

A

ui.R

library(shiny)
library(shinyjs)

shinyUI(fluidPage(
  bootstrapPage(



  )
)
)

Server.R

library(shiny)
library(shinyjs)
mydb=dbConnect(MySQL(),user='',password='123',dbname='test1',host='localhost')
shinyServer(function(input, output,session){


column(4, 
                    textInput("name", label = "NAME:", 
                              value ='')),
             column(4, 
                    textInput("address", label = "Address:", 
                              value =''))

column(2,
                              actionButton("add", "ADD"))



 observeEvent(
    input$add, 
 output$ui123 <- renderUI({isolate({

dbSendQuery(mydb,paste("INSERT INTO table1(name,address) VALUES ('",input$name,"','",input$address,"');",sep=" ")) 
})}))


  }



})

If the input to address contains apostrophe (for example:First street's),then it shows an error that the mysql statement contains some error. How can this data be entered without any error into Mysql in R shiny.

Marc B
  • 356,200
  • 43
  • 426
  • 500
Rad
  • 59
  • 1
  • 8

1 Answers1

-1

maybe juste add slashes (like php) :

gsub(pattern = "'", replacement = "\\\\'", x = "test'")

?

prise6
  • 136
  • 1
  • 7